Assigning a Segment Programmatically

Overview

You might want to assign a visitor to a segment programmatically instead of using the Convert interface options to add it.

Steps

  1. Find out the segment id. This is a bit tricky as you have to add the audience (that you have designated as a segment) to an experience to be able to find it. 

    You can find this on the Audience card under the Experience Summary. Please see the image below for an example:

    save image
  2. Code it. Adapt the following example to programmatically add a visitor to a segment:

    See the Pen LJXveq by Convert.com (@gcrewe) on CodePen.




  3. Test your code as a normal visitor in an incognito browser window and verify that the cookie _conv_v has the segment id recorded on the seg key. You can find more information about the cookie structure in the following article.
Have more questions? Submit a request

Comments