Skip to content

Commit

Permalink
Create datalayer-product.js
Browse files Browse the repository at this point in the history
  • Loading branch information
ekuplu committed Aug 7, 2022
1 parent a699d45 commit 9d25bac
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions datalayer-product.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{% comment %} Product view data layer v2.0 - part of "Shopify GA4 Kit" by Analyzify
Visit https://analyzify.app/shopify-google-analytics/ga4 for complete tutorial
{% endcomment %}

<script type="text/javascript">
window.dataLayer = window.dataLayer || [];

window.appStart = function(){
{% assign template_name = template.name %}

window.productPageHandle = function(){
var productName = "{{ product.title | remove: "'" | remove: '"' }}";
var productId = "{{ product.id }}";
var productPrice = "{{ product.price | money_without_currency }}";
var productBrand = "{{ product.vendor | remove: "'" | remove: '"' }}";
var productCollection = "{{ product.collections.first.title | remove: "'" | remove: '"' }}"
window.dataLayer.push({
event: 'analyzify_productDetail',
productName: productName,
productId: productId,
productPrice: productPrice,
productBrand: productBrand,
productCategory: productCollection,
});
};
{% case template_name %}
{% when 'product' %}
productPageHandle()
{% endcase %}
}

appStart();
</script>

0 comments on commit 9d25bac

Please sign in to comment.