Useful Custom JavaScript Variables for Google Tag Manager

Comments:6

  1. Hi
    I need to use a custom js variable to change the name of a data layer product impression variable from ‘style’ to ‘variant’. I also need to add a new variable that is the first 3 characters of another existing variable. I’m trying to work out the JS to write to accomplish these 2 goals.
    thanks

    1. Hi Rebbret,
      To get the first three characters of a variable you can make a custom JS variable like this:
      function(){
      var str = {{your variable}};
      var strFirstThree = str.substring(0,3);
      return strFirstThree;
      }

      I’m not totally sure what you mean about changing the name of the data layer variable. Please clarify with a sample of your code and what you’d like to happen, and I’ll be happy to help further.

Leave a Reply

Your email address will not be published.