Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get values from dataLayer object

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

like image 966
Rakesh Sharma Avatar asked Aug 18 '17 11:08

Rakesh Sharma


People also ask

How do you retrieve data from a data layer?

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.

How do I get the dataLayer variable in Google Tag Manager?

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.)

What does the dataLayer push () command return?

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.


2 Answers

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

like image 182
Moritz Avatar answered Sep 29 '22 05:09

Moritz


Print the Data Layer in a table console.table(dataLayer); and note the index value it will show for Linker.

enter image description here

Then you may use dataLayer[XXX] as XXX being the index value for Linker.

like image 44
Husain Al Faraj Avatar answered Sep 29 '22 03:09

Husain Al Faraj