html Shopify DataLayer Checkout
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html Shopify DataLayer Checkout相关的知识,希望对你有一定的参考价值。
{% if first_time_accessed %}
<script>
(function(dataLayer){
var customer_type = ({{customer.orders_count}} > 1) ? 'repeatcustomer' : 'newcustomer';
var discounts = "{{ order.discounts | map: 'code' | join: ',' | upcase}}";
function strip(text){
return text.replace(/\s+/, ' ').replace(/^\s+/, '').replace(/\s+$/, '');
}
function firstof(){
for(var i = 0; i < arguments.length; i++){
if(arguments[i]) return arguments[i];
}
return null;
}
var products = [];
{% for line_item in order.line_items %}
products.push({
'id': firstof(strip('{{line_item.sku}}'), strip('{{line_item.product_id}}')),
'name': strip('{{line_item.product.title}}'),
'category': strip('{{line_item.product.type}}'),
'brand': strip('{{line_item.vendor}}'),
'variant': strip('{{line_item.variant.title}}'),
'coupon': "{{ line_item.discounts | map : 'code' | join: ',' | upcase}}",
'price': {{line_item.price | times: 0.01}},
'quantity': {{line_item.quantity}}
});
{% endfor %}
dataLayer.push({
'event': 'checkoutComplete',
'customerType': customer_type,
'ecommerce': {
'currencyCode': '{{shop.currency}}',
'purchase': {
'actionField': {
'id': '{{order.order_number}}',
'affiliation': strip('Shopify {{shop.name}}'),
'revenue': {{order.total_price | times: 0.01}},
'tax': {{order.tax_price | times: 0.01}},
'shipping': {{order.shipping_price | times: 0.01}},
'coupon': discounts
},
'products': products
}
}
});
setTimeout(function(){
// Clear the ecommerce data for subsequent hits.
dataLayer.push({ 'ecommerce': null });
}, 3);
}(window.dataLayer = window.dataLayer || []));
</script>
{% endif %}
<script>
function containsGTMStart(dl){
var i = 0;
dl.map(function(e){ if('gtm.start' in e) i++; });
return !!i;
}
(function(w,d,s,l,i){
w[l]=w[l]||[];
// attempts to prevent GTM from loading twice.
if(containsGTMStart(w[l])) return false;
w[l].push({'gtm.start':new Date().getTime(),event:'gtm.js'});
var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),
dl=l!='dataLayer'?'&l='+l:'';
j.async=true;
j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl;
f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXXX');
</script>
以上是关于html Shopify DataLayer Checkout的主要内容,如果未能解决你的问题,请参考以下文章
html Shopify的链接选项帮助方法。请参阅:http://docs.shopify.com/manual/configuration/store-customization/advanced-
html Shopify API过滤产品价格
html 示例Shopify产品说明格式。
html [Shopify]每个变体显示多个图像
html Shopify无限滚动
在NestJS 中添加对Shopify 的WebHook 验证