1{% if template.name == 'search' %}
2 <script>
3 window.monetateQ = window.monetateQ || [];
4 window.monetateQ.push([
5 "setPageType",
6 "search"
7 ]);
8
9 const searchParams = new URLSearchParams(window.location.search);
10 console.log(searchParams.has('q'));
11 var searchTerm = searchParams.get('q');
12
13 window.monetateQ.push([
14 "addSearch", {
15 "searchTerm": searchTerm,
16 "searchType": "site"
17 }
18 ]);
19 </script>
20{% endif %}
21
22{% if template.name == 'collection' %}
23 <script>
24 window.monetateQ = window.monetateQ || [];
25 window.monetateQ.push(['setPageType', '{{ template.name }}']);
26 window.monetateQ.push([
27 "addProducts", [{% for product in collection.products %}"{{ product.id }}",{% endfor %}]
28 ]);
29 {% if cart.item_count > 0 %}
30 window.monetateQ.push([
31 "addCartRows", [
32 {%- for item in cart.items -%}
33 {
34 "productId": "{{ item.product_id }}",
35 "quantity": "{{ item.quantity }}",
36 "unitPrice": "{{ item.final_price | money | remove: "$" }}",
37 "sku": "{{ item.sku }}",
38 "currency": "{{ cart.currency.iso_code }}"
39 },
40 {% endfor %} ]
41 ]);
42 {% endif %}
43 window.monetateQ.push([
44 "trackData"
45 ]);
46 </script>
47 {% elsif template.name == 'product' %}
48 <script>
49 window.monetateQ = window.monetateQ || [];
50 window.monetateQ.push(['setPageType', '{{ template.name }}']);
51 window.monetateQ.push(['addProductDetails', [
52 {% for variant in product.variants %}{
53 productId: '{{ product.id }}',
54 sku: '{{ variant.sku }}'
55 },{% endfor %}
56 ]]);
57 window.monetateQ.push(['trackData']);
58 </script>
59 {% elsif template.name == 'search' %}
60 <script>
61 window.monetateQ = window.monetateQ || [];
62 window.monetateQ.push(['setPageType', '{{ template.name }}']);
63 window.monetateQ.push([
64 {% assign search_results = search.results | where: "object_type", "product" %}
65 "addProducts", [{% for product in search_results %}"{{ product.id }}",{% endfor %}]
66 ]);
67 {% if cart.item_count > 0 %}
68 window.monetateQ.push([
69 "addCartRows", [
70 {%- for item in cart.items -%}
71 {
72 "productId": "{{ item.product_id }}",
73 "quantity": "{{ item.quantity }}",
74 "unitPrice": "{{ item.final_price | money | remove: "$" }}",
75 "sku": "{{ item.sku }}",
76 "currency": "{{ cart.currency.iso_code }}"
77 },
78 {% endfor %} ]
79 ]);
80
81 {% endif %}
82
83 window.monetateQ.push([
84 "trackData"
85 ]);
86 </script>
87 {% elsif template.name == 'home' %}
88 <script>
89 const collectionItems = document.querySelectorAll('.product-card');
90 let monetateData = [];
91
92 collectionItems.forEach((item) => {
93 const id = item.getAttribute('data-id');
94 monetateData.push(id);
95 });
96
97 window.monetateQ = window.monetateQ || [];
98 window.monetateQ.push(['setPageType', '{{ template.name }}']);
99 window.monetateQ.push(['addProducts', monetateData]);
100 {% if cart.item_count > 0 %}
101 window.monetateQ.push([
102 "addCartRows", [
103 {%- for item in cart.items -%}
104 {
105 "productId": "{{ item.product_id }}",
106 "quantity": "{{ item.quantity }}",
107 "unitPrice": "{{ item.final_price | money | remove: "$" }}",
108 "sku": "{{ item.sku }}",
109 "currency": "{{ cart.currency.iso_code }}"
110 },
111 {% endfor %} ]
112 ]);
113 {% endif %}
114 window.monetateQ.push(['trackData']);
115 </script>
116 {% else %}
117 <script>
118 window.monetateQ = window.monetateQ || [];
119 window.monetateQ.push(['setPageType', '{{ template.name }}']);
120 {% if cart.item_count > 0 %}
121 window.monetateQ.push([
122 "addCartRows", [
123 {%- for item in cart.items -%}
124 {
125 "productId": "{{ item.product_id }}",
126 "quantity": "{{ item.quantity }}",
127 "unitPrice": "{{ item.final_price | money | remove: "$" }}",
128 "sku": "{{ item.sku }}",
129 "currency": "{{ cart.currency.iso_code }}"
130 },
131 {% endfor %} ]
132 ]);
133 {% endif %}
134
135 window.monetateQ.push(['trackData']);
136 </script>
137{% endif %}