Skip to content

Instantly share code, notes, and snippets.

@vhsu
Last active December 1, 2016 15:33
Show Gist options
  • Save vhsu/bdf00cfdff2cff267f9f09d7244359b9 to your computer and use it in GitHub Desktop.
Save vhsu/bdf00cfdff2cff267f9f09d7244359b9 to your computer and use it in GitHub Desktop.
Get Datalyer value
// Get single datalayer value from gtm in vanilla javascript
google_tag_manager["GTM-XXXXXXX"].dataLayer.get('variable')
// Retrieve value from google tag manager datalayer object in vanilla javascript
google_tag_manager["GTM-XXXXXXX"].dataLayer.get('variable')['purchase']['actionField']['revenue']
// To fetch the value from a javacript variable inside gtm of custom html you would use the following code from the same object
variable.purchase.actionField.revenue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment