I want to get some values from dataLayer object of google tag manager. In chrome tag assistance i am getting values like this
[
{
"gtm.start": 1503053374849,
"event": "gtm.js",
"gtm.uniqueEventId": 0
},
{
"event": "gtm.dom",
"gtm.uniqueEventId": 1
},
{
"event": "gtm.load",
"gtm.uniqueEventId": 2
},
{
"Linker": "_ga=53655374"
}
]
I need to get the "Linker" value. i tried dataLayer[3].Linker
but it gives me "undefined" or blank also same for dataLayer[1].event
(it's blank not return value = "gtm.dom")
When i try dataLayer[0].event
it's return correct 'gtm.js'
Please help me how to get "Linker" value
Just head on over to your console, type in “dataLayer,” navigate to your key:value pair, and follow the nested path to the key you want to identify. Save, refresh, and go through let's go through another test transaction. Buy a couple items, get to the order received page.
Set up the data layer variableClick Variables. Under User-Defined Variables, click New. Click Variable Configuration and select Data Layer Variable as the variable type. In the Data Layer Variable Name field, enter the key exactly as it was written in the code (e.g. bookTitle, not book title.)
The return value, assuming you are referring to when you pasted the code into the console, indicates whether a GTM tag fired in response to the push. "true" means that no tags fired, and "false" means that a tag fired.
You can access the pushed data via the google tag manager javascript-api. The variable part will be the container-id of your GTM container. Make shure you adress the correct one.
google_tag_manager['<container-id>'].dataLayer.get('gtm.start');
//result e.g.: 1210115541132
The result will be the last value of the datalayers state
Print the Data Layer in a table console.table(dataLayer);
and note the index
value it will show for Linker
.
Then you may use dataLayer[XXX]
as XXX
being the index
value for Linker
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With