Jarvis
Jarvis

Reputation: 63

How to get google tag manger variable value in custom HTML

I have dynamic values in my Datalayer which I want to access from my custom HTML in Google Tag Manager

Custom HTML in tag : {A pixel image for tracking orders}

<img src="https://httpool-secure.net/p.ashx?o=59&e=51&f=img&t={{transactionId}}&etc={{transactionTotal}}" width="1" height="1" border="0"

My DataLayer Object :

[{
    "event": "ordersuccess",
    "transactionId": 86886,
    "transactionAffiliation": "Powai",
    "transactionTotal": 158,
    "transactionTax": 17.5,
    "transactionProducts": [{
        "sku": "2395",
        "name": "Masala Calzone ",
        "category": "OTHERS",
        "price": "70",
        "quantity": "2"
    }]
}, {
    "gtm.start": 1454584525056,
    "event": "gtm.js"
}, {
    "event": "gtm.dom"
}, {
    "event": "gtm.load"
}]

Data Layer Variable transactionId

Data Layer Variable transactionTotal

Now when I publish my tag I get errors :

Unknown variable 'transactionTotal' found in a tag. Edit the tag and remove the reference to the unknown variable.

Unknown variable 'transactionId' found in a tag. Edit the tag and remove the reference to the unknown variable.

How to associate the variables to my tag ???

Upvotes: 6

Views: 14757

Answers (4)

user3325400
user3325400

Reputation: 29

As some have mentioned, you need to use the variable's name when referencing it in HTML. For example: If I setup a variable named 'Order Total' but the Data Layer Variable Name is orderTotal you'll want to use 'Order Total' in your HTML as displayed below.

alert({{Order Total}});

Upvotes: 1

mayrop
mayrop

Reputation: 701

Even though the correct answer is already given, I really understood it until I saw the documentation in this repository: https://github.com/BKWLD/data-layer-events

The key is part of the README.md file in the Setup section.

Basically you need to setup variables of type Data Layer Variable with the parameter name you're giving, in your case that would be transactionId, then the variable becomes available on the tags and it will match the JS parameters you are providing.

Upvotes: 2

Saleem Ahmed
Saleem Ahmed

Reputation: 2999

The top field sets the variable name in GTM Panel. Please use that name as the variable name . You should be using the name of the DataLayer Variables that you've named in this input box, and not the name of the dataLayer parameters themselves

Upvotes: 2

nyuen
nyuen

Reputation: 8907

I take no credit for this possible answer as it was already mentioned in comments (props to @EikePierstorff), but as a formality, here it is:

You should use the name of the DataLayer Variables that you've defined, and not the name of the dataLayer parameters themselves:

<img src="https://httpool-secure.net/p.ashx?o=59&e=51&f=img&t={{transaction_id}}&etc={{total transaction}}" ...

Upvotes: 3

Related Questions