0

I am having a hard time finding a way to find an element on page {click_id} and replace it with a value previously captured from a first party cookie.

I have a script on my site that generates a "click_id" value which is stored in the cookie. I have outbound links on my site which have a placeholder {click_id}.

mylink.foo/?utm_campaign={click_id}&utm_source=hello

On click event, I want the "click_id" value to be injected in the {click_id} placeholder.

  • You need to use double curly braces eg. {{click_id}}, also, make sure click_id is defined before you try to use it in your code. – Matus Apr 30 '18 at 09:33

1 Answers1

0

GTM doesn't have a built-in feature for modifying URLs, only for reading them, so you'll have to write some custom code. The flow should be as follows:

  1. Create click_id variable which reads click id value from wherever it needs to
  2. Create tag: which parses outbound links on your page and inserts click_id into them:

Note: you said you "have a script on my site that generates a "click_id" value which is stored in the cookie". So you have to be careful about "race conditions" (ie the GTM tag running before your script). What I advise is to move all your tagging/tracking scripts to GTM, and use GTM tag sequencing to make sure they all run following the necessary order.

Max
  • 12,794
  • 30
  • 90
  • 142