Post purchase upsell page

If your Shopify store uses a post-purchase upsell page (for an upsell app) additional setup is required to track the upsell purchases.

Create a conversion rule in Realize

  1. Open Realize, and select the account (top, left) that you will use to track conversions.

  2. In the sidebar (left), select Tracking.

  3. Click on + New conversion (far right). Then select Install events using code and click Continue.

  4. Type in a Conversion Name of your choice - e.g. Upsell Purchase.

    This is a descriptive name for your convenience.

  5. For Conversion Type, select EVENT:

  6. Leave Fixed Value blank (since this value is dynamic).

    For additional guidelines, see the Help Center.

  7. UnderCategory, select Make Purchase.

  8. Edit the Event Name to read upsell_purchase (or similar).

  9. Make sure that the Include in total value and Include in total conversions checkboxes are checked.

  10. (Optional) If desired, tweak the values of the remaining fields.

    For additional guidelines, see the Help Center.

  11. Scroll down to the Event Code section, and select the relevant dynamic parameters.

    Note how the code snippet updates accordingly.
    For detailed guidelines, see: Track dynamic conversion values

  12. Review your chosen settings, and click on Create (bottom, right):

Add a code snippet to Shopify

  1. In your Shopify dashboard, select Settings > Checkout.

  2. Scroll down to Post-purchase page section.

  3. Copy the code snippet provided below and paste it under Additional scripts.

    Mouse over the code snippet and click on copy (top, right).

  4. Edit the script and fill in your own Taboola Account ID on the first line.

    See: Tips & techniques > Obtain your Account ID

  5. Once you are done with your editing, click on Save.

    🚧

    Make sure to fill in your own Taboola Account ID.

    <script>
    const TABOOLA_ACCOUNT_ID = '123'; // Replace '123' with your own Taboola Account ID.
    
    window._tfa = window._tfa || [];
    !function (t, f, a, x ) {
      if (!document.getElementById(x)) {
        t.async = 1;t.src = a;t.id=x;f.parentNode.insertBefore(t, f);
      }
    }(document.createElement('script'),
    document.getElementsByTagName('script')[0],
    '//cdn.taboola.com/libtrc/unip/' + TABOOLA_ACCOUNT_ID + '/tfa.js',
    'tb_tfa_script');
    
    
    Shopify.on('CheckoutAmended', function (newOrder, previousOrder) {
      try {
        console.log('[TaboolaPixel] CheckoutAmended event fired', newOrder, previousOrder);
    
        const oldItems = (previousOrder.lineItems || []).map(function (line) {
          return line.id;
        });
    
        const addedItems = (newOrder.lineItems || []).filter(function (line) {
          return oldItems.indexOf(line.id) < 0;
        });
    
        console.log('[TaboolaPixel] Previous item IDs:', oldItems);
        console.log('[TaboolaPixel] Newly added items:', addedItems);
    
        if (addedItems.length === 0) {
          console.log('[TaboolaPixel] No new items detected — event will not be fired');
          return;
        }
    
        const totalRevenue = addedItems.reduce(function (sum, item) {
          return sum + (item.finalPrice * item.quantity);
        }, 0);
    
      const totalQuantity = addedItems.reduce(function (sum, item) {
        return sum + item.quantity;
      }, 0);
    
      const taboolaEvent = {
        notify: 'event',
        name: 'upsell_purchase',
        id: TABOOLA_ACCOUNT_ID,
        revenue: totalRevenue,
        currency: newOrder.currency || 'USD',
        orderid: newOrder.id || '',
        quantity: totalQuantity
      };
    
        console.log('[TaboolaPixel] Final event object:', taboolaEvent);
    
        _tfa.push(taboolaEvent);
        console.log('[TaboolaPixel] Event pushed to _tfa');
    
      } catch (error) {
        console.error('[TaboolaPixel] Error in CheckoutAmended handler:', error);
      }
    });
    </script>