Add a contact to a segment or tag from tracking code

I want to add a contact to a specific segment or set a tag after some action in the website happened. I am already setting custom fields. Is it possible to do it from the Javascript tracking code?



Regards,

Xavier

I want to add a contact to a specific segment or set a tag after some action in the website happened. I am already setting custom fields. Is it possible to do it from the Javascript tracking code?

Regards,
Xavier

Try modifying the tracking pixel JS you inserted on your site

Change this:

mt('send', 'pageview');

Into something like:

mt('send', 'pageview', { customFieldName: variableWithValueToSend });

Hi,

The docs say this in section “Tracking Pixel tracking”:

“The contact’s tags can be changed by using the tags query parameter. Multiple tags can be separated by comma. To remove a tag, prefix it with a dash (minus sign).”

Is it possible to do the same with the Javascript tracking code?

Xavier

Hi,

Thanks, but I am already doing this, and it works fine. I want to set tags, not just custom fields - it is possible with the pixel, but it does not work with the JS code.

Xavier

OK, sorry, obviously I misunderstood your question.

Since you said you would like to (alternatively to tagging) add a contact to a segment, would this workaround work for you:

  • generate a filter-based segment where all the leads you want to address fall under… if you’re trying to mark unidentified leads from a certain webpage, then make a segment with condition “email is empty” (it works, I just tried)

  • generate a segment-driven campaign that contains a “Request dynamic content” decision

  • in the campaign, add a “Modify contact’s segments” action under the green part of the dynamic content request

  • using javascript, try generating a dynamic content placeholder when your action occurs - try dynamically appending into the DOM this: <div class="mautic-slot" data-slot-name="dwc"></div>

I have not tested this approach and I am not sure whether Mautic detects DOM changes on-the-fly or not. If I am correct, the “Request dynamic content” decision checks if the DWC slot is present in the DOM.

If this should happen when MTC is loaded, maybe you could try reloading MTC after you’ve put the DWC in the DOM. As mentioned, this is untested but I would give it a try.

I hope this somehow helps.

Best,
D.