← All articles

Blog / TikTok

TikTok

Shopify TikTok Pixel Script: Working Custom Pixel Code (2026)

July 20, 2026·2 min read

If you need to install the TikTok Pixel manually on your Shopify store using a custom script, you can no longer use the old Additional Scripts checkout box. Since Shopify is deprecating legacy scripts on August 26, 2026, you must use a Shopify Custom Pixel (Settings → Customer events). Below is the complete, production-ready TikTok Pixel script for Shopify Custom Pixels.

The Complete TikTok Pixel Script for Shopify

Copy and paste this script directly into your Shopify Admin under Settings → Customer events → Add custom pixel. Be sure to replace YOUR_TIKTOK_PIXEL_ID with your actual TikTok Pixel ID.

// Initialize TikTok Pixel Sdk inside Shopify Sandbox
const script = document.createElement("script");
script.src = "https://analytics.tiktok.com/i18n/pixel/events.js?sdkid=YOUR_TIKTOK_PIXEL_ID&lib=ttq";
script.async = true;
document.head.appendChild(script);

window.ttq = window.ttq || [];
window.ttq.methods = ["page","track","identify","instances","debug","on","off","once","ready","alias","group","enableCookie","disableCookie","holdConsent","revokeConsent","grantConsent"];
window.ttq.setAndDefer = function(t,e){t[e]=function(){t.push([e].concat(Array.prototype.slice.call(arguments,0)))}};
for(var i=0;i {
  const checkout = event.data.checkout;
  const value = checkout.totalPrice?.amount ?? 0;
  const currency = checkout.totalPrice?.currencyCode ?? "USD";
  
  // Build line items array for TikTok product catalog matching
  const contents = (checkout.lineItems || []).map((item) => ({
    content_id: String(item.variant?.id || item.product?.id || ""),
    content_name: item.title || "",
    quantity: item.quantity || 1,
    price: item.variant?.price?.amount || 0
  }));

  ttq.track("CompletePayment", {
    value: value,
    currency: currency,
    content_type: "product",
    contents: contents,
    // Event ID is critical for Conversions API (CAPI) deduplication
    event_id: event.id
  });
});

Key Features of this Script

  • Sandboxed Isolation: Fully compatible with Shopify's Checkout Extensibility iframe sandbox.
  • Dynamic Totals: Automatically parses purchase totals, currencies, and line items from the checkout payload.
  • CAPI Deduplication: Maps Shopify's unique event.id to TikTok's event_id parameters, preventing double conversion reports.

Why Manual Scripts Fail Later

While copy-pasting a script works today, custom scripts are vulnerable to silent failures. If Shopify updates its checkout schema, or your consent management app blocks marketing scripts, the pixel will stop firing with no visual error on your site. You will only notice when your TikTok ad campaigns drop in performance due to optimization blindness.

For an automated and monitored solution, use PixelWard. It automatically generates Custom Pixel code for TikTok, Google Ads, and Meta, and alerts you instantly via Email, Slack, or Telegram if any pixel stops reporting events.

Migrate your tracking in minutes, not weekends.

PixelWard converts your Additional Scripts into working Custom Pixels and alerts you if tracking ever goes silent.

Install PixelWard