Pixel tracking on the post-purchase page

If your store has installed an app that adds a post-purchase page to your store's checkout, then any custom pixel tracking that you use on your store might not capture certain tracking events. Custom tracking pixels that are added to your store'sAdditional scriptsbox track events on only the order status page, which comes after the post-purchase page in the checkout. If a customer leaves your store on the post-purchase page, then no events on the order status page are tracked.

To ensure that you capture conversion events properly, you can add a script that tracks events on the post-purchase page. This script can also track additional purchases that are made from the post-purchase page, such as upsells. After you add a post-purchase page script, you need to adjust your order status page script to ignore events that are already captured by the post-purchase page script.

You need to change how your store tracks events only if you use a custom tracking pixel. For example, if you set up Google Analytics through欧宝体育官网入口首页>Preferences, then it already captures events correctly on your post-purchase page.

Considerations

The post-purchase page additional script is similar to the order status page additional scripts, but with a few key differences:

  • The script is added to the post-purchase page, not the order status page.
  • The field allows only JavaScript. Liquid code isn't accepted.
  • The only HTML tag allowed is{%endif%}

    Available APIs

    您可以使用JavaScript全局跟踪scripts access to the data that they need. The accessible data is available underwindow.Shopify.

    Tracking purchases made on the post-purchase page

    To track additional purchases that are made through the post-purchase page, you can subscribe to theShopify.onevent.

    After you subscribe, the following actions occur whenever a post-purchase changeset is successfully applied:

    • Your handler is called with twoOrder-type arguments:orderandoutdated order.
    • The globals underwindow.Shopifyare updated so that the scripts can use the updated data.

    Handlers subscribed to this event can have as little as 500 ms to execute. Make sure to load any dependencies that you need ahead of time.

    Add the post-purchase page script

    Before you add the post-purchase page script, for the post-purchase field to display in your Shopify Admin, make sure that youset up either the Google and YouTube channel或下载第三方售后应用的情况。

    Steps:

    1. From your Shopify admin, go toSettings>Checkout.
    2. In thePost-purchase additional scriptsfield, enter your script.
    3. ClickSave.

    Example script

    You can use the following basic script template to help you build your own post-purchase page script. This example script uses Google Analytics to track the initial conversion, and explains how to track additional purchases. This example is very simple and your final script will likely differ from it.

    Example script files

    Example script for the order status page:

    异步src = " https://www.googletagmanager.co <脚本m/gtag/js?id=G-FYNQ742HTX"> 

    Example script for the post-purchase page:

    异步src = " https://www.googletagmanager.co <脚本m/gtag/js?id=G-FYNQ742HTX"> 

    References

    The following table contains the type definitions for the attributes that are exposed to post-purchase additional scripts throughwindow.Shopify:

    Field Definition
    window.Shopify
    shop Thedetails of the shopfrom where the order was placed.
    order Thedetails of the order.
    pageUrl The current page's URL.
    wasPostPurchasePageSeen Whether the customer viewed the post-purchase page during this checkout. It will befalsewhen rendering for the first time, and真正的otherwise, such as if the page is reloaded.
    on(event: string, handler: function): void Subscribes to anevent. Currently, only theCheckoutAmendedevent is supported.
    off(event: string, handler: function): void Unsubscribeshandlerfrom the givenevent. Currently, only theCheckoutAmendedevent is supported.
    Shop
    id The ID of the shop.
    currency The store's currency inISO 4217format. For example, USD. For more details, refer toshop.currency.
    Order
    id The order's internal identifier.
    number The integer representation of the order name. For example, 1025.
    checkoutToken The checkout's internal identifier.
    customer Thecustomerassociated with the order.
    lineItem Theline itemsfor the order.
    subtotalPrice The subtotal price of all the items in the order after both line-item and cart discounts have been applied. The subtotal doesn't include taxes (unless taxes are included in the prices), shipping costs, or tips.
    totalPrice The total price of the order.
    currency TheISO 4217code of the order's currency.
    discounts The sum of the amount of the discounts applied to the order.
    Customer
    id The ID of the customer.
    email The email address of the customer.
    acceptsMarketing Whether the customer had accepted marketing. It will be真正的if the customer accepts marketing, andfalseif not.
    hasAccount Whether the customer email is associated with a customer account. It will be真正的if the email is listed on a customer account, andfalseif not. For more details, refer tocustomer.has_account.
    firstName The first name of the customer.
    lastName The last name of the customer.
    ordersCount The total number of orders that the customer has placed.
    totalSpent The total amount that the customer has spent on all orders.
    LineItem
    finalLinePrice The combined price of all the items in the line item. This is equal toline_item.final_pricemultiplied byline_item.quantity.
    finalPrice The price of the line item, including all line-level discount amounts.
    lineLevelTotalDiscount The total amount of all discounts applied to the line item specifically. This doesn't include discounts that are added to the cart.
    optionsWithValues An array of selected values from the item's product options. For more details, refer toline_item.options_with_values.
    originalLinePrice The combined price of the quantity of items included in the line, before discounts were applied. This is equal toline_item.original_pricemultiplied byline_item.quantity.
    originalPrice The original price of the line item before discounts were applied.
    price The unit price of the line item. The price reflects any discounts that are applied to the line item. Available only to stores located in Germany or France.
    product Theproductof the line item.
    properties An array of custom information for an item that has been added to the cart. For more information, refer toline_item.properties.
    quantity The quantity of the line item.
    title The title of the line item. For more information, refer toline_item.title.
    variant Thevariantof the line item.
    Product
    id The ID of the product.
    type The type of the product.
    ProductVariant
    id The ID of the variant.
    sku The SKU of the variant.
    CartDiscount
    id The discount application's internal identifier.
    code The code of the discount, if it has one.
    type The type of the discount. Possible values are:automatic,discount_code,manual, andscript.
    amount The total amount that the price of the order is reduced by the discount.
Ready to start selling with Shopify?Try it free