GTM Data Layer: Difference between revisions
Jump to navigation
Jump to search
(Created page with "This JavaScript is added in the header of the website: <syntaxhighlight lang="javascript"> window.dataLayer = window.dataLayer || []; function gtag() { dataLayer.push(arguments); } </syntaxhighlight> The `dataLayer` collection is sent to Google Tag Manager. The `gtag()` function is a convenience for sending this data. After the document content is loaded, it can be used to send event data to GTM. <syntaxhighlight lang="javascript"> gtag("event", "purchase", {...") |
No edit summary |
||
| Line 44: | Line 44: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Pointing that out because on the website, there can be calls to `gtag()`, while in a tutorial video I was watching the code displayed was `dataLayer.push()` | |||
[[Category:Web Development]][[Category:Analytics]] | [[Category:Web Development]][[Category:Analytics]] | ||
Latest revision as of 16:27, 29 December 2024
This JavaScript is added in the header of the website:
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
The dataLayer collection is sent to Google Tag Manager.
The gtag() function is a convenience for sending this data.
After the document content is loaded, it can be used to send event data to GTM.
gtag("event", "purchase", {
transaction_id: "BFH_5478",
value: 10,
tax: 0,
shipping: 0,
currency: "USD",
payment_method: "PayPal credit card",
items: [
{
item_id: "PB-DL",
item_name: "Playful Beginnings, with Overview, the Teacher's Guide",
affiliation: "Barchowsky Fluent Handwriting Website",
coupon: "",
discount: 0,
price: 10.00,
item_brand: "Barchowsky Fluent Handwriting",
item_variant: "download",
quantity: 1
},
]
});
The above has the same effect as
dataLayer.push({event: "purchase", ...});
Pointing that out because on the website, there can be calls to gtag(), while in a tutorial video I was watching the code displayed was dataLayer.push()