-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathqubit-events-transaction.liquid
104 lines (95 loc) · 4.86 KB
/
qubit-events-transaction.liquid
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
<!-- Qubit Transaction Events start -->
<script>
!function(){function n(){function n(n){p.level=n}function e(n,e){p.info(n,"event emitted"),e=c(e||{}),e.meta=e.meta||{},e.meta.type=n,u.push(e),r(),v.listeners=f(v.listeners,function(n){return!n.disposed})}function o(n,e,o){function r(){return p.info("Replaying events"),t(function(){s(v.events,function(t){c.disposed||l(n,t.meta.type)&&e.call(o,t)})}),f}function i(){return p.info("Disposing event handler"),c.disposed=!0,f}p.info("Attaching event handler for",n);var c={type:n,callback:e,disposed:!1,context:o||window};v.listeners.push(c);var f={replay:r,dispose:i};return f}function t(n){p.info("Calling event handlers"),a++;try{n()}catch(n){p.error("UV API Error",n.stack)}a--,r()}function r(){if(0===u.length&&p.info("No more events to process"),u.length>0&&a>0&&p.info("Event will be processed later"),u.length>0&&0===a){p.info("Processing event");var n=u.shift();v.events.push(n),t(function(){s(v.listeners,function(e){if(!e.disposed&&l(e.type,n.meta.type))try{e.callback.call(e.context,n)}catch(n){p.error("Error emitting UV event",n.stack)}})})}}function i(n,e,o){var t=v.on(n,function(){e.apply(o||window,arguments),t.dispose()});return t}function s(n,e){for(var o=n.length,t=0;t<o;t++)e(n[t],t)}function c(n){var e={};for(var o in n)n.hasOwnProperty(o)&&(e[o]=n[o]);return e}function l(n,e){return"string"==typeof n?n===e:n.test(e)}function f(n,e){for(var o=n.length,t=[],r=0;r<o;r++)e(n[r])&&t.push(n[r]);return t}var u=[],a=0,p={info:function(){p.level>n.INFO||console&&console.info&&console.info.apply(console,arguments)},error:function(){p.level>n.ERROR||console&&console.error&&console.error.apply(console,arguments)}};n.ALL=0,n.INFO=1,n.ERROR=2,n.OFF=3,n(n.ERROR);var v={on:o,emit:e,once:i,events:[],listeners:[],logLevel:n};return v}"object"==typeof module&&module.exports?module.exports=n:window&&void 0===window.uv&&(window.uv=n())}();
</script>
<!-- TODO: Update below path with the one provided to you by Qubit -->
<script src="//static.goqubit.com/smartserve-XXXX.js" async defer></script>
<script>
(function () {
var config = {
eventNamespace: false
}
if(config.eventNamespace) {
config.ns = config.eventNamespace + "."
} else {
config.ns=""
}
uv.emit(config.ns + 'ecView', {
type: "confirmation"
})
{% comment %}
User - https://help.shopify.com/themes/liquid/objects/customer
{% endcomment %}
{% if customer %}
uv.emit(config.ns + 'ecUser', {
user: {
id: "{{ customer.id | json }}",
email: {{ customer.email | json }},
firstName: {{ customer.first_name | json }},
lastName: {{ customer.last_name | json }}
}
})
{% endif %}
{% comment %}
Transaction - https://help.shopify.com/themes/liquid/objects/checkout
{% endcomment %}
var basketSummary = {
subtotal: {
currency: {{ shop.currency | json }},
value: {{ checkout.line_items_subtotal_price | money_without_currency | remove: ',' }}
},
total: {
currency: {{ shop.currency | json }},
value: {{ checkout.total_price | money_without_currency | remove: ',' }}
},
tax: {
currency: {{ shop.currency | json }},
value: {{ checkout.tax_price | money_without_currency | remove: ',' }}
},
shippingPrice: {
currency: {{ shop.currency | json }},
value: {{ checkout.shipping_price | money_without_currency | remove: ',' }}
},
discount: {
currency: {{ shop.currency | json }},
value: {{ checkout.discounts_amount | money_without_currency | remove: ',' }}
},
subtotalIncludingTax: {
currency: {{ shop.currency | json }},
value: {{ checkout.line_items_subtotal_price | plus: checkout.tax_price | money_without_currency | remove: ',' }}
},
shippingMethod: {{ shipping_method.title | json }}
}
var transactionSummary = {
id: "{{ order.order_number | json }}"
}
uv.emit(config.ns + 'ecBasketTransactionSummary', {
transaction: transactionSummary,
basket: basketSummary
})
{% for item in line_items %}
uv.emit(config.ns + 'ecBasketItemTransaction', {
transaction: transactionSummary,
basket: basketSummary,
product: {
productId: "{{ item.product.id | json}}",
sku: {{ item.sku | default: item.variant_id | json }},
name: {{ item.product.title | json }},
manufacturer: {{ item.product.vendor | json }},
price: {
currency: {{ shop.currency | json }},
value: {{ item.product.price | money_without_currency | remove: ',' }}
},
url: window.location.protocol + "{{ item.product.url }}",
categories: ["{{ item.product.type}}"]
},
quantity: {{ item.quantity }},
subtotal: {
currency: {{ shop.currency | json }},
value: {{ item.line_price | money_without_currency | remove: ',' }}
}
})
{% endfor %}
}());
</script>
<!-- Qubit Transaction Events end -->