GTM Data Layer

From Littledamien Wiki
Revision as of 16:26, 29 December 2024 by Video8 (talk | contribs) (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", {...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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&#39;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", ...});