-
Notifications
You must be signed in to change notification settings - Fork 3
/
tag-rocket-hello-retail.html
108 lines (89 loc) · 4.11 KB
/
tag-rocket-hello-retail.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<script data-cfasync="false">
/*
Web Site Advantage: Tag Rocket Hello Retail [v1.5]
Hello Retail API support
https://bigcommerce.websiteadvantage.com.au/tag-rocket/articles/tag-rocket-api/
Copyright (C) 2021 Web Site Advantage
*/
!function(w,t){
var partnerId = 'REPLACE_WITH_YOUR_ID';
var productIdentifier = function(product) {return ''+product.productId}; // productId, productSku, sku (product or variant)
// var productIdentifier = 'url'; // use this line instead if you want to use product urls
w[t]=w[t]||{};var T=w[t];T.i=T.i||[];if(!T.init)T.init=function(f){T.i.push(f)};
T.init(function(){
var scriptTagAdded = false;
function addScriptTag() {
if (!scriptTagAdded) {
scriptTagAdded = true;
T.addScriptTag('https://d1pna5l3xsntoj.cloudfront.net/scripts/company/awAddGift.js#'+partnerId);
}
}
_awev=w._awev||[];
if (T.consent.targetingAdvertising) {
addScriptTag();
}
T.on('.*',function(data, eventName){
// https://apidocs.helloretail.com/register-email-on-tracking-user ??
switch(eventName) {
case "ConsentChanged":
if (T.consent.targetingAdvertising) {
addScriptTag();
}
break;
case "CartItemChanged":
// https://apidocs.helloretail.com/cart-tracking/tracking-a-complete-cart
// *******************************************
var cartData = {
total: data.cart.grandTotal || data.cart.cartAmount,
url: '{{settings.base_url}}{{urls.cart}}'
};
addDetails(data.cart, cartData);
// console.log('ADDWISH_PARTNER_NS.api.cart.setCart', cartData)
_awev.push(["bind_once", "context_ready", function() {
ADDWISH_PARTNER_NS.api.cart.setCart(cartData);
}]);
// https://apidocs.helloretail.com/cart-tracking/tracking-when-a-visitor-adds-a-product-to-cart
// *******************************************
// if (data.change > 0) {
// var productData = {productNumber: ''+data.productId};
// // console.log('ADDWISH_PARTNER_NS.api.cart.addProduct', productData)
// _awev.push(["bind_once", "context_ready", function() {
// ADDWISH_PARTNER_NS.api.cart.addProduct(productData);
// }]);
// }
break;
case "CheckoutStep5OrderCompleted":
// https://apidocs.helloretail.com/conversion-tracking
// *******************************************
var cartData = {
total: data.orderAmount,
orderNumber: data.orderId
};
addDetails(data, cartData);
// console.log('ADDWISH_PARTNER_NS.api.conversion.track_sale', cartData)
_awev.push(["bind_once", "context_ready", function() {
ADDWISH_PARTNER_NS.api.conversion.track_sale(cartData);
}]);
break;
}
});
})
function addDetails(cart, cartData) {
if (productIdentifier == 'url') {
cartData.urls = [];
for(var i=0; i < cart.items.length; i++) {
cartData.urls.push(cart.items[i].url);
};
}
else {
cartData.productNumbers = [];
for(var i=0; i < cart.items.length; i++) {
cartData.productNumbers.push(''+productIdentifier(cart.items[i]));
};
}
{{#if customer.email}}
cartData.email = '{{customer.email}}';
{{/if}}
}
}(window,"TagRocket")
</script>