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
I think you are asking this:
When you put the code in the custom html.
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)
But I can not track how the
29
or30
is coming from.As we can know
["escape", ["macro", 29], 7]
is present aVariable
Given the limited context and details I assume that:
I see mutliple issues in your code:
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.
Refer to the documentation of _cb to identify the proper method.