GTM implementation (EN)
Would you like to send your events to Squeezely via GTM? On this page you can find example code for every standard event. The code below is based on an enhanced e-commerce datalayer, for which you can also use smart tracking you can also use this code. If one of your datalayers doesn't match, this can be a good solution because smart tracking measures all or nothing.
- 1 Variables
- 2 Tags
- 2.1 Viewcontent
- 2.2 Viewcategory
- 2.3 AddToCart
- 2.4 RemoveFromCart
- 2.5 Purchase
Variables
(type: Datalayer variable, version 2)
DLV - products product page: ecommerce.detail.products
DLV - order: ecommerce.purchase.actionField
DLV - purchase products: ecommerce.purchase.products
DLV - purchase actionfield: ecommerce.purchase.actionField
DLV - category: ecommerce.impressions.0.category
DLV - products cart: ecommerce.add.products
DLV - remove cart products: ecommerce.remove.products
Alternatively, you can create an "ecommerce" variable and address the relevant objects per tag, for example:
{{DLV - ecommerce}}.detail.products
Tags
Custom HTML tag, each script must be between <script type="text/javascript"> and </script>. The trigger = event or relevant pageview.
Do you want to add extra fields? Add them to the data object before sending, for example data.email = {{email address}}.
Viewcontent
var products = {{DLV - products product page}};
var sqProducts = [];
var data = {};
data.event = "ViewContent";
for (var i = 0; i < products.length; i++) {
sqProducts[i] = [];
if (products[i].id != null) {
sqProducts[i].id = products[i].id;
}
if (products[i].name != null) {
sqProducts[i].name = products[i].name;
}
if (products[i].price != null) {
sqProducts[i].price = products[i].price;
}
}
data.products = sqProducts;
window._sqzl = window._sqzl || [];
window._sqzl.push(data);
Viewcategory
var data = {};
data.event = "ViewCategory";
if ({{DLV - category}} != null) {
data.category_id = {{DLV - category}};
}
window._sqzl = window._sqzl || [];
window._sqzl.push(data);
AddToCart
var products = {{DLV - products cart}};
var sqProducts = [];
var data = {};
data.event = "AddToCart";
for (var i = 0; i < products.length; i++) {
sqProducts[i] = [];
if (products[i].id != null) {
sqProducts[i].id = products[i].id;
}
if (products[i].name != null) {
sqProducts[i].name = products[i].name;
}
if (products[i].price != null) {
sqProducts[i].price = products[i].price;
}
if (products[i].quantity != null) {
sqProducts[i].quantity = products[i].quantity;
}
}
data.products = sqProducts;
window._sqzl = window._sqzl || [];
window._sqzl.push(data);