Assigning a Segment Programmatically

This Article Will Help You:


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:



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

    window._conv_q = window._conv_q || [];
    _conv_q.push(["placeVisitorIntoSegment","1001583"]);


  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.

keyword: placeVisitorIntoSegment