Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
Hello, I'm moving on Custom Pixel for Google Tag Manger Tracking. Currently I use the following code in the Additional order status page scripts:
<!-- Google Tag Manager --> <script>(function(w,d,s,l,i){w[l]=w[l]||[];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-NH7PPMP');</script> <!-- End Google Tag Manager --> {% comment %} Purchase data layer v2.1 - part of "Shopify GA4 Kit" by Analyzify Visit https://analyzify.app/shopify-google-analytics/ga4 for complete tutorial {% endcomment %} {% assign template_name = template.name %} <script type="text/javascript"> window.dataLayer = window.dataLayer || []; window.appStart = function(){ window.allPageHandle = function(){ window.dataLayer.push({ event: "ga4kit_info", contentGroup: "{{ template_name }}", {% if customer %} userType: "member", customer: { id: "{{- checkout.customer.id | json -}}", lastOrder: "{{- customer.last_order.created_at | date: '%B %d, %Y %I:%M%p' -}}", orderCount: "{{- checkout.customer.orders_count | json -}}", totalSpent: "{{- checkout.customer.total_spent | times: 0.01 | json -}}", tags: {{- checkout.customer.tags | json -}} } {% else %} userType: "visitor", {% endif %} }); }; allPageHandle(); {% if first_time_accessed and post_purchase_page_accessed != true %} var shippingPrice = "{{shipping_price | money_without_currency }}".replace(",", "."); var totalPrice = "{{checkout.total_price | money_without_currency }}".replace(",", "."); var taxPrice = "{{tax_price | money_without_currency }}".replace(",", "."); var orderItemsName = []; var orderItemsId = []; var orderItemsCategory = []; var orderItemsBrand = []; var orderItemsType = []; var orderItemsPrice = []; var orderItemsSku = []; var orderItemsvariantId = []; var orderItemsQuantity = []; var orderItemsvariantTitle = []; var totalQuantity = 0; {% for line_item in checkout.line_items %} orderItemsName.push("{{ line_item.product.title | remove: "'" | remove: '"'}}"); orderItemsId.push("{{ line_item.product_id }}"); orderItemsPrice.push("{{ line_item.price | times: 0.01 }}"); orderItemsSku.push("{{ line_item.sku | remove: "'" | remove: '"' }}"); orderItemsQuantity.push("{{ line_item.quantity }}"); orderItemsvariantId.push("{{ line_item.variant_id }}"); orderItemsvariantTitle.push("{{ line_item.variant.title }}"); orderItemsCategory.push("{{ line_item.product.collections.last.title | remove: "'" | remove: '"' }}"); orderItemsBrand.push("{{ line_item.vendor | remove: "'" | remove: '"' }}"); orderItemsType.push("{{ line_item.product.type | remove: "'" | remove: '"' }}"); totalQuantity += {{ line_item.quantity }}; {% endfor %} window.dataLayer.push({ page_type: "purchase", event: "analyzify_purchase", currency: "{{ shop.currency }}", totalValue: totalPrice, totalValueStatic: totalPrice, currencyRate: window.Shopify.currency.rate, shipping: shippingPrice, tax: taxPrice, payment_type: "{{order.transactions[0].gateway}}", {% if order.name %} transaction_id: "{{order.name | remove: "'" | remove: '"'}}", {% else %} transaction_id: "{{checkout.id | remove: "'" | remove: '"'}}", {% endif %} productName: orderItemsName, productId: orderItemsId, productBrand: orderItemsBrand, productCategory: orderItemsCategory, productVariantId: orderItemsvariantId, productVariantTitle: orderItemsvariantTitle, productSku: orderItemsSku, productType: orderItemsSku, productPrice: orderItemsPrice, productQuantity: orderItemsQuantity, }); {% endif %} } appStart(); </script>
But when I move the script in the Custom Pixel, it give me some errors. Have I ignore the errors? Can you see if there are errors and provide me the correct script?
Thank you very much.
Hey, @FrancescoMi89
Happy to help. What are some of the error messages that you received when moving the script in the Custom Pixel?
We can go from there!
Dirk | Social Care @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit the Shopify Help Center or the Shopify Blog
Hello, I attach the screenshot of the error. Anyway, I'm not expert on the topic, do you think is an acceptable solution move the code from checkout to pixel, as it is?
Ok I see the errore. Is the </script> tag. Anyway if I cancel the script tag it give me other errors, I start to think isn't an acceptable solution to copy and paste the script from checkout to pixel...
Hello prestigehome,
Your datalayer is not going to work properly.
we have developed a datalayer to track all the conversions for shopify website. this datalayer is compatible with any currency and has enhanced e-commerce tracking following GA4 schema.
you can check out the datalayer.
All the e-commerce event you can preview from google tag assistant or console LAX environment.
Hey Community 👋 Did you know that March 15th is National Everything You Think Is W...
By JasonH Apr 1, 2025Discover how to increase the efficiency of commerce operations with Shopify Academy's l...
By Jacqui Mar 26, 2025Shopify and our financial partners regularly review and update verification requiremen...
By Jacqui Mar 14, 2025