Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 

Pushing Ecommerce Data

Setting the ecommerce currency

Set the currency to an standard currency code such as EUR, GBP, or USD.

GTM::transactionCurrency('EUR');

outputs:

dataLayer.push({
    "ecommerce": {
        "currencyCode": "EUR"
    }
});

Pushing a product impression

To push a product impression pass an array of product fields.

$impression = [
    'name'     => 'Triblend Android T-Shirt',
    'id'       => '12345',
    'price'    => '15.25',
    'brand'    => 'Google',
    'category' => 'Apparel',
    'variant'  => 'Gray',
    'list'     => 'Search Results',
    'position' => 1
];
GTM::productImpression($product)

outputs:

dataLayer.push({
    "ecommerce": {
        "currencyCode": "EUR",
        "impressions": [
            {
                "name": "Triblend Android T-Shirt",
                "id": "12345",
                "price": "15.25",
                "brand": "Google",
                "category": "Apparel",
                "variant": "Gray",
                "list": "Search Results",
                "position": 1
            }
        ]
    }
});

Pushing a product promotion impression

$product = [
    'id'       => 'JUNE_PROMO13',
    'name'     => 'June Sale',
    'creative' => 'banner1',
    'position' => 'slot1'
];
GTM::productPromoImpression($product)

outputs:

dataLayer.push({
    "ecommerce": {
        "promoView": {
            "promotions": [
                {
                    "id": "JUNE_PROMO13",
                    "name": "June Sale",
                    "creative": "banner1",
                    "position": "slot1"
                }
            ]
        }
    }
});

Pushing a product detail view

$product = [
    'name'     => 'Triblend Android T-Shirt',
    'id'       => '12345',
    'price'    => '15.25',
    'brand'    => 'Google',
    'category' => 'Apparel',
    'variant'  => 'Gray'
];
GTM::productDetail($product);

outputs:

dataLayer.push({
    "ecommerce": {
        "detail": {
            "products": [
                {
                    "name": "Triblend Android T-Shirt",
                    "id": "12345",
                    "price": "15.25",
                    "brand": "Google",
                    "category": "Apparel",
                    "variant": "Gray"
                }
            ]
        }
    }
});

Pushing an add to cart action

$product = [
    'name'     => 'Triblend Android T-Shirt',
    'id'       => '12345',
    'price'    => '15.25',
    'brand'    => 'Google',
    'category' => 'Apparel',
    'variant'  => 'Gray',
    'quantity' => 1
];
GTM::addToCart($product);

outputs:

dataLayer.push({
    "ecommerce": {
        "add": {
            "products": [
                {
                    "name": "Triblend Android T-Shirt",
                    "id": "12345",
                    "price": "15.25",
                    "brand": "Google",
                    "category": "Apparel",
                    "variant": "Gray",
                    "quantity": 1
                }
            ]
        }
    },
    "event": "addToCart"
});

Pushing a remove from cart action

$product = [
    'name'     => 'Triblend Android T-Shirt',
    'id'       => '12345',
    'price'    => '15.25',
    'brand'    => 'Google',
    'category' => 'Apparel',
    'variant'  => 'Gray',
    'quantity' => 1
];
GTM::removeFromCart($product);

outputs:

dataLayer.push({
    "ecommerce": {
        "remove": {
            "products": [
                {
                    "name": "Triblend Android T-Shirt",
                    "id": "12345",
                    "price": "15.25",
                    "brand": "Google",
                    "category": "Apparel",
                    "variant": "Gray",
                    "quantity": 1
                }
            ]
        }
    },
    "event": "removeFromCart"
});

Pushing a purchase transaction and items

$transaction = [
    'id'          => 'T12345',
    'affiliation' => 'Online Store',
    'revenue'     => '35.43',
    'tax'         => '4.90',
    'shipping'    => '5.99',
    'coupon'      => 'SUMMER_SALE'
];
GTM::purchase($transaction);

$product = [
    'name'     => 'Donut Friday Scented T-Shirt',
    'id'       => '67890',
    'price'    => '33.75',
    'brand'    => 'Google',
    'category' => 'Apparel',
    'variant'  => 'Black',
    'quantity' => 1
];
GTM::purchaseItem($product);

outputs:

dataLayer.push({
    "ecommerce": {
        "purchase": {
            "actionField": {
                "id": "T12345",
                "affiliation": "Online Store",
                "revenue": "35.43",
                "tax": "4.90",
                "shipping": "5.99",
                "coupon": "SUMMER_SALE",
                "currencyCode": null
            },
            "products": [
                {
                    "name": "Donut Friday Scented T-Shirt",
                    "id": "67890",
                    "price": "33.75",
                    "brand": "Google",
                    "category": "Apparel",
                    "variant": "Black",
                    "quantity": 1
                }
            ]
        }
    }
});

Refunding a transaction or items

Refunding a transaction

GTM::refundTransaction(10001)

outputs:

window.dataLayer = window.dataLayer || [];
dataLayer.push({
    "ecommerce": {
        "refund": {
            "actionField": {
                "id": 1001
            }
        }
    }
});

Refunding a transaction item

GTM::refundItem(1001, 999, 1)

outputs:

window.dataLayer = window.dataLayer || [];
dataLayer.push({
    "ecommerce": {
        "refund": {
            "actionField": {
                "id": 1001
            },
            "products": [
                {
                    "id": 999,
                    "quantity": 1
                }
            ]
        }
    }
});