-
Insert the First script into the theme.
-
In the store dashboard, click "Online Store" -> "Themes"
-
Click the "Customize" button for the current theme
-
At the bottom of the sidebar, click "Theme Actions" -> "Edit Code"
-
In the code editor, click "Layout" -> "theme.liquid"
-
In the
<head>
tag somewhere, paste:
<script> function clearCookie (name) { document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:00 GMT' } function setCookie (name, value) { document.cookie = name + '=' + value; } function getSource () { const queryParams = new URLSearchParams(window.location.search) return queryParams.get('advref') } document.addEventListener('DOMContentLoaded', function() { var source = getSource(); if (source) { setCookie('advref', source); } }); </script>
-
-
Add the second script to the Checkout admin
-
In the store dashboard, click "Settings" -> "Checkout"
-
Scroll down to the "Order Processing" section
-
In the "Additional Scripts" field, paste:
{% if first_time_accessed %} <script> function postJSON (url, json) { return fetch(url, { method: 'post', headers: { Accept: 'application/json, text/plain, */*', 'Content-Type': 'application/json', }, body: JSON.stringify(json), }); } function getCookie (name) { var match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)')); if (match) { return match[2]; } } document.addEventListener('DOMContentLoaded', function() { var advCookie = getCookie('advref'); if (advCookie) { var data = { order_number: '{{ order_number }}', customer: { id: '{{ customer.id }}', city: '{{ customer.default_address.city }}', state: '{{ customer.default_address.province }}', country: '{{ customer.default_address.country }}', }, 'purchased': [ {% for line_item in checkout.line_items %} { product_id: '{{ line_item.product_id }}', quantity: '{{ line_item.quantity }}', title: '{{ line_item.product.title }}', variant: '{{ line_item.product.variant }}', }, {% endfor %} ], currency: '{{ checkout.currency.iso_code }}', total: '{{ checkout.total_price | money }}', }; postJSON('https://api.adv.gg/v1/register-conversion/', { source: advCookie, data: data, }); } }, false); </script> {% endif %}
-
EcomGraduates/advocate-shopify-scripts
Scripts for doing conversion tracking with shopify stores
LiquidMIT