My Post-Purchase Upsell Tags Won't Fire in Shopify Checkout

Using the Shopify Post-Purchase Upsells & are having trouble capturing purchase/upsell data in GA4 and Google Ads?

Overview:

Scenario: You're using an app like Zipify, Carthook, or others that trigger a post-purchase upsell funnel in the native Shopify checkout.

You've followed our guide to install the Shopify source.

For some marketing destinations like Facebook and Universal Analytics, you're seeing data populate accurately.

But in others (like GA4 or Google Ads), you're not seeing data populate. Yikes!

Here's the bad news: Shopify only allows a marketing tag as little as 500 milliseconds to fire. Universal Analytics & Facebook seem to be fine firing in that little timeframe. But GA4 & Google Ads tags don't seem to make it in that short time frame.
But here's the good news: You can setup GA4 and Google Ads to fire their tracking on the final Thank You Page while keeping Facebook & UA firing on the upsell pages!

Step 1: Add a New DataLayer Code to your Order Status Page

In your Shopify Checkout Settings > Scroll to Order Status Page > "Additional Scripts".

Add the below code into the Additional Scripts section:

{% if first_time_accessed %}

    <script>

    var elevarLineItems = []

    window.addEventListener('load', function(){

        window.dataLayer = window.dataLayer || [];

        window.dataLayer.push({

            "event": "thankyou_purchase",

            "user_properties":{

              "customer_id": "{{ customer.id | remove: "'" }}",

              "customer_email": "{{ customer.email }}",

              "customer_first_name": "{{ customer.first_name }}",

              "customer_phone": "{{ customer.default_address.phone }}",

              "customer_last_name": "{{ customer.last_name }}",

              "customer_city": "{{ customer.default_address.city }}",

              "customer_zip": "{{ customer.default_address.zip }}",

              "customer_address_1": "{{ customer.default_address.address1 }}",

              "customer_address_2": "{{ customer.default_address.address2 }}",

              "customer_country": "{{ customer.default_address.country_code }}",

              "customer_province": "{{ customer.default_address.province }}",

              "customer_order_count": "{{customer.orders_count}}",

              "customer_total_spent": "{{customer.total_spent}}"

            },

            "ecommerce": {

                "currencyCode": "{{ order.currency }}",

                "purchase": {

                    actionField: {

                        {%- if checkout.order_id -%}

                            id: {{- checkout.order_id | json -}},

                        {%- else -%}

                            id: {{- checkout.id | json -}},

                        {%- endif -%}

                        {%- if checkout.order_name -%}

                            order_name: {{- checkout.order_name | json -}},

                        {%- endif -%}

                        affiliation: {{- shop.name | json -}},

                        revenue: "{{- checkout.total_price | times: 0.01 | json -}}",

                        tax: "{{- checkout.tax_price | times: 0.01 | json -}}",

                        shipping: "{{- checkout.shipping_price | times: 0.01 | json -}}",

                        {% if checkout.discount_applications %}

                            coupon: {{ checkout.discount_applications[0].title | json }},

                        {% endif %}

                        {%- if order.subtotal_price -%}

                            subTotal: "{{- order.subtotal_price | times: 0.01 | json -}}",

                        {%- elsif checkout.subtotal_price -%}

                            subTotal: "{{- checkout.subtotal_price | times: 0.01 | json -}}",

                        {%- endif -%}

                        productSubTotal: "{{- checkout.line_items_subtotal_price | times: 0.01 | json -}}",

                        discountAmount: "{{- checkout.discounts_amount | times: 0.01 | json -}}"

                        },

                    "products": [

                     {%- for line_item in checkout.line_items -%}

                        {
                            "name": {{- line_item.product.title | json -}},

                            {%- if line_item.sku != blank -%}

                                "id": {{- line_item.sku | json -}},

                            {%- else -%}

                                "id": "{{- line_item.product_id | json -}}",

                            {%- endif -%}

                            "product_id": "{{- line_item.product_id | json -}}",

                            "variant_id": "{{- line_item.variant_id -}}",

                            "price": "{{- line_item.final_price | times: 0.01 | json -}}",

                            "brand": {{- line_item.vendor | json -}},

                            "category": {{- line_item.product.type | json -}},

                            "variant": {{- line_item.variant.title | json -}},

                            "quantity": "{{- line_item.quantity | json -}}",

                        },

                    {%- endfor -%}

                    ],

                }

            }

        });

    }, false);

    </script>

{% endif %}

Step 2: Create a New Trigger in Google Tag Manager

In your Google Tag Manager Account, navigate to Triggers > New

Create an Event Trigger mimicking the below > Press Save

Step 3: Update Your Desired Purchase Tags

Navigate to Tags > Find the Purchase Tag for the marketing destination that isn't able to fire on Shopify's Upsell Page (e.g. GA4 or Google Ads).

Remove the Event - purchase trigger > Add the newly created _Event - thankyou_purchase trigger > Press Save.

Make your changes go live by pressing Submit > then Publish.

For Google Ads Only

Google Ads will deduplicate transactions sent based on transaction_id. The same transaction_id is passed on the post_purchase page as the thank_you page. To capture the most possible website conversions in Google Ads it is recommended that you add both the Event - purchase & Event - thankyou_purchase as triggers. Update both Google Ads Conversion - Purchase & Google Ads Remarketing - Purchase tags as shown below.

Note: This is not recommended for other marketing destinations as most use different criteria for deduplication and would lead to duplication

Make your changes go live by pressing Submit > then Publish.

Step 4: [Optional] QA the new tags with Google Tag Manager's Preview Mode

Follow our guide to QA your tags in Google Tag Manager (GTM) preview mode.