skip to Main Content

I need to link a GTM variable in a custom HTML tag, how does that work exactly?

<script>
var parsedUtm = JSON.parse({{utmCookie}} || '{}'); // works
var utm_source = parsedUtm['utmSource'] || {{utmSource}} || ''; // works

  
  _cb.push(['setVisitorIdentifier', '{{utmSource}}']); // no idea how this works :)
</script>

2

Answers


  1. I think you are asking this:

    When you put the code in the custom html.

    enter image description here

    You can check the gtm.js loading in your website.

    Here is the code Google Tag Manager will transform to

    (I am not sure to use the word compile or translate)

    enter image description here

    console.log("", ["escape", ["macro", 29], 7], ["escape", ["macro", 30], 7], "")
    

    But I can not track how the 29 or 30 is coming from.

    As we can know ["escape", ["macro", 29], 7] is present a Variable

    Login or Signup to reply.
  2. Given the limited context and details I assume that:

    • You are using GTM
    • You store utms in a utmCookie
    • You want to assign utm_source as a user variable for some tool named _cb

    I see mutliple issues in your code:

    var utm_source = parsedUtm['utmSource'] || {{utmSource}} || '';
    

    If you already have a GTM variable {{utmSource}} why would you need to parse the cookie? Either parse the cookie to retrieve the value or use the GTM variable but not both.

    Without knowing what _cb is it is difficult for us to know exactly what might be the issue. But you are setting the visitor identifier which would usually be a unique identifier. Setting something like a utm source would rather be setting a user property so it will probably be another method you would have to use.

    _cb.push(['setVisitorIdentifier', '{{utmSource}}']);
    

    Refer to the documentation of _cb to identify the proper method.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search