xrts
xrts

Reputation: 11

use google tag manager custom HTML tag to populate data on pages

I have a question about gtm.

so currently I have created a script that can create all the data I need into datalayer this is how the data layer looks like (from page source code):

<script> 
dataLayer = [{"visitorLoginState":"Logged out","visitorType":"NOT LOGGED     IN","visitorLifetimeValue":0,"visitorExistingCustomer":"No"}];
</script>

but all this is generated from my store, but they key would be to be able to use these variables through GTM.

so inside GTM UI i created a custom html tag and added:

<script>
dataLayer.push({'event': 'visitorLoginState'});
</script>

I also created a custom macro->data layer variable with the name of "visitorLoginState" hoping that it would show "NO" instead of visitorLoginState in the response. but it just showing "visitorLoginState"

Upvotes: 1

Views: 1382

Answers (1)

Daffy
Daffy

Reputation: 89

I am new to GTM too and getting to grips with it all.

From what I can see it looks like you are using macros and the dataLayer incorrectly.

You are running a script to add another row called event to the datalayer whilst already declaring what you want in the data layer. So initially the output in the source would be along the lines of:

visitorLoginState: Logged Out
visitortype: Not Logged In
ETC...

With the script you have added in GTM it would go to:

visitorLoginState: Logged Out
visitortype: Not Logged In
event: visitorLoginState
ETC

What you want to do is actually create a macro called visitorLoginState with the Type of Data Layer Variable, using the Data Layer Variable Name of visitorLoginState (and so forth).

From there you can create a Rule in GTM which will activate something based on what is returned in the data layer.

So your Rule could be:

visitorLoginState equals Logged out.

You could then have your script in the tags part of GTM which would say something like:

 <script>
 dataLayer.push({'event': 'No'});
 </script>

Upvotes: 0

Related Questions