0

I'm using GTM for my remarketing campaign. If a user visits the website from a newsletter, the URL will be personalised with a special parameter https://www.mywebsite.com/?client_id=1234

I'm using the value "1234" a variable for my remarketing tags, and I have different tags based on page visited (homepage, product page, cart..etc)

Everything works well on the landing page, but when user visits another page, the parameter in my URL disappears, so my variable gets a "null" value.

How can I save the initial value in the variable during the whole session, despite visiting several pages ?

1 Answers1

1

I have tested the following solution successfully.

First you have to create a URL Variable (for example {{VAR - URL - client_id}}) like this:

enter image description here

Then you have to create a custom JavaScript variable and add this code:

function(){
  var clientString = {{VAR - URL - client_id}};

  if(sessionStorage.getItem('client_id') === null && typeof clientString != 'undefined'){
    sessionStorage.setItem('client_id', clientString);    
  } 
  return sessionStorage.getItem('client_id');
}

This will store the client_id in the sessionStorage for the length of the session and it will be available on the other pages as well.

Nedo
  • 199
  • 1
  • 4