Orbitall
Orbitall

Reputation: 661

Google Tag Manager with Json-ld - datalayer variable not returning value

I am trying to do this on ecommerce product pages. I have the following custom HTML tag firing on all pageviews of product pages. Its using datalayer varaibles, the debuging/preview tool shows the correct value for each variable:

{
    “@context” : “http://schema.org”,  
    “@type”: “Product”,
    “name”: {{productName}},
    “image”: {{productImage}},
    “description”: {{productDescription}},
    “brand”: {
    “@type”: “Thing”,
    “name”: {{productBrand}}
 },
    “offers”: {
    “@type”: “Offer”,
    “priceCurrency”: “GBP”,
    “price”: {{productPrice}}
    }
}

I think I followed the template correctly, but this is what shows up in Google’s structured data testing tool:

“@context” : “http://schema.org”,
“@type”: “Product”,
“name”: google_tag_manager[“GTM-PHZTTZ”].macro(‘gtm1469648023100’),
“image”: google_tag_manager[“GTM-PHZTTZ”].macro(‘gtm1469648023101’),
“description”: google_tag_manager[“GTM-PHZTTZ”].macro(‘gtm1469648023102’),

“brand”: {
“@type”: “Thing”,
“name”: google_tag_manager[“GTM-PHZTTZ”].macro(‘gtm1469648023103’)},

“offers”: {
“@type”: “Offer”,
“priceCurrency”: “GBP”,
“price”: google_tag_manager[“GTM-PHZTTZ”].macro(‘gtm1469648023104’)
}

It seems to return the name of the macros from GTM’s data model rather than the value? Did I do something wrong?

Upvotes: 0

Views: 829

Answers (1)

Eike Pierstorff
Eike Pierstorff

Reputation: 32770

You did not do anything wrong - this is an expresssion that will evaluate to the value of your datalayer variable.

google_tag_manager[“GTM-PHZTTZ”].macro(‘gtm1469648023100’) quite simply means "return the value from the variable with the internal id of 1469648023100 from the tag manager instance with the id GTM-PHZTTZ".

The Googlebot executes Javascript when it indexes the site and will be able to parse the JSON directly (and crawlers that do not execute Javascript will quite probably unable to work with Json, so that's not a concern).

Upvotes: 1

Related Questions