-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmooch.liquid
71 lines (64 loc) · 2.88 KB
/
smooch.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
<script>
function loadScript(src, callback) { var s, r, t; r = false; s = document.createElement('script'); s.type = 'text/javascript'; s.src = src; s.onload = s.onreadystatechange = function() { if ( !r && (!this.readyState || this.readyState == 'complete') ) { r = true; callback(); } }; t = document.getElementsByTagName('script')[0]; t.parentNode.insertBefore(s, t); } loadScript('https://cdn.smooch.io/smooch.min.js', function() {
var skSizeChat = document.getElementById("sk-no-sizing");
//var skPurchase = document.getElementById('sk-purchase');
// Welcome whisper user after 30s
var timeout;
Smooch.on('ready', function(message) {
timeout = setTimeout(function() {
Smooch.track("sk-welcome-delay");
}, 30000);
});
Smooch.on('widget:opened', function() {
clearTimeout(timeout);
});
// Store users language as property
Smooch.on('ready', function() {
var language = window.navigator.userLanguage || window.navigator.language;
Smooch.updateUser({
properties: {
'lang': language
}
});
//skPurchase.onload = function() {
// Smooch.track("sk-purchase");
//};
// Whipser for sizing inquiries
skSizeChat.onclick = function() {
Smooch.open();
Smooch.track("sk-no-sizing");
}
});
var skPromise = Smooch.init({
appToken: "PRIVATEAPPTOKENHERE",
serviceUrl: "https://app.smooch.io",
customText: {
introductionText: 'We try to be quick, so ask us anything!',
introAppText: 'Chat with us below or from your favorite app, email, or SMS.',
inputPlaceholder: 'Type a message....'
}
});
{% if customer %}
skPromise.then(function() {
Smooch.updateUser({
userId: "{{ customer.email }}",
givenName: "{{ customer.first_name }}",
surname: "{{ customer.last_name }}",
email: "{{ customer.email }}",
properties: {
"Customer Account": "{{ shop.secure_url }}/admin/customers/{{ customer.id }}",
{% if customer.orders_count > 0 %}
"Orders Count": "{{ customer.orders_count }}",
{% endif %}
{% if customer.total_spent > 0 %}
"Lifetime Spent": "{{ customer.total_spent | money }}",
{% endif %}
{% if customer.last_order %}
"Last Order": "{{ customer.last_order.created_at | date: "%B %d, %Y %I:%M%p" }}"
{% endif %}
},
});
});
{% endif %}
});
</script>