Shopify Integration

Track affiliate conversions on Shopify stores. The SDK auto-detects the Shopify Analytics API, falls back to dataLayer, and supports GoKwik, ShipRocket, and Razorpay alternative checkouts.

Overview

Affclix tracks Shopify purchases through a layered detection strategy:

  • Shopify Analytics API — primary method; reads ShopifyAnalytics.lib.page() and order metadata
  • dataLayer push — fallback for headless / custom themes using GTM
  • Alternative checkouts — GoKwik, ShipRocket, Razorpay event listeners

Prerequisites

  • Shopify store with theme file access (Online Store 2.0 or legacy)
  • Affclix account with tracking domain configured
  • Additional Scripts permission for Checkout Extensibility (Plus plans)

Installation

Add the snippet to your theme.liquid file inside the <head> tag. For Shopify Plus also add to checkout.liquid.

01

Open your theme editor

Go to Online Store → Themes → Actions → Edit code.

02

Open theme.liquid

Find the file under Layout → theme.liquid.

03

Paste the SDK snippet

Add the code below just before the closing </head> tag.

How It Works

01

Shopify Detection

SDK detects window.ShopifyAnalytics and reads page metadata, shop currency, and cart token.

02

Analytics API

If present, ShopifyAnalytics.lib.page() provides order data without relying on Liquid variables — useful for headless setups.

03

dataLayer Fallback

If Analytics API is unavailable, the SDK listens for a purchase event on window.dataLayer (standard GTM e-commerce schema).

04

Conversion Fired

Order data is normalised and posted to your Affclix postback endpoint. Duplicate orderId values within 24 h are automatically suppressed.

Alternative Checkouts

For Indian Shopify stores using third-party checkout providers, map the provider payload with getCheckoutData() inside the provider success callback, then fire trackConversion().

GoKwik

JavaScript
// Inside your GoKwik order-success callback:
var data = AffclixSDK.integrations.shopify.getCheckoutData(event, 'gokwik');
AffclixSDK.trackConversion({
  campaignID:     'YOUR_CAMPAIGN_ID',
  eventName:      'purchase',
  conversionData: data
});

ShipRocket Checkout

JavaScript
var data = AffclixSDK.integrations.shopify.getCheckoutData(event, 'shiprocket');
AffclixSDK.trackConversion({
  campaignID:     'YOUR_CAMPAIGN_ID',
  eventName:      'purchase',
  conversionData: data
});

Razorpay Magic Checkout

JavaScript
var data = AffclixSDK.integrations.shopify.getCheckoutData(event, 'razorpay');
AffclixSDK.trackConversion({
  campaignID:     'YOUR_CAMPAIGN_ID',
  eventName:      'purchase',
  conversionData: data
});
Provider Detection

When a provider is specified, the SDK attaches a postMessage listener to the checkout iframe. No manual order data mapping is required.

Conversion Fields

FieldTypeRequiredDescription
orderIdstringYesUnique order number for deduplication
revenuenumberYesOrder total (excluding shipping unless desired)
currencystringNoISO 4217 code — defaults to store currency
couponstringNoDiscount code applied at checkout
itemsarrayNoLine items for product-level commission rules
providerstringNoAlternative checkout: gokwik, shiprocket, razorpay

Testing

Enable testMode so conversions are recorded with an isTest flag and will not credit any affiliate.

JavaScript
AffclixSDK.init({
  trackingDomain: 't.yourdomain.com',
  testMode: true
});
order_date Guard

The SDK checks order.created_at and will not fire a conversion if the order is more than 2 hours old. This prevents duplicate fires on page reloads of the confirmation page.

Rate this article
★★★★★
Thanks for rating!

Was this article helpful?