Mission: The objective is to send the JSON data to Google Tag Manager.
Issue at Hand: Unfortunately, Shopify Documentation does not provide a liquid variable for 'referrer'.
Potential Fix: One possible solution is to create a variable using JavaScript.
My Approach:
I have developed a script that appends the URL of the website from where visitors are coming.
The appended website URL is then captured and converted into a variable.
The variable
{{ ref }}
is inserted into the JSON.
Upon inspection of the element, it was noticed that the 'referrer' field in the JSON was empty.
Requesting assistance on this matter.
<script type="text/javascript">
$(document).ready(function () {
var content = document.referrer;
$(".referrer").append(content);
});
</script>
{% capture ref %}
<div class="referrer">Referrer: </div>
{% endcapture %}
<script type="text/javascript">
dataLayer.push({
‘userEmail’ : ‘{{ customer.email }}’,
‘productCategory’ : ‘{{ collection.title }}’,
‘productName’ : ‘{{ product.title }}’,
‘price’ : ‘{{ sca_price | money }}’,
‘originalPrice’ : ‘{{ sca_price | money }}’,
‘cartItems’ : ‘{{ cart.item_count }}’,
‘currency’ : ‘{{ shop.currency }}’,
‘referrer’ : ‘{{ ref }}’, // issue persists
‘productRating’ : ‘’,
‘reviewCount’ : null,
‘event’ : null
});
</script>