Etkö ehdi seurata digimarkkinoinnin uusimpia käänteitä? Uutiskirjeemme auttaa sinua pysymään kärryillä

Tuottaako digimarkkinointisi? Varaa maksuton auditointi

ChatGPT Ads Pixel Shopify – Installation Guide

ChatGPT Ads Pixel Shopify – Installation Guide
Erik Back |

Sisällysluettelo

    You can install the ChatGPT Ads pixel on Shopify without an app, without Google Tag Manager, and without touching your theme — using Shopify's built-in Custom Pixel system. This guide walks through the full installation step by step and gives you the complete pixel code ready to copy.

    What you need before you start

    You only need two things: your Pixel ID — found in OpenAI Ads Manager under Tools → Conversions → Pixel — and admin access to your Shopify store. A Conversions API (CAPI) key is not required for this setup.

    Installation: Shopify Customer Events

    1. In Shopify admin, go to Settings → Customer events
    2. Click Add custom pixel and name it e.g. ChatGPT Ads Pixel
    3. Set Customer Privacy to: Permission = Required, categories Marketing and Analytics
    4. Paste the code below into the editor and replace YOUR_PIXEL_ID with your own
    5. Click Save

    Setting Permission to Required means Shopify's native consent banner controls when the pixel fires — no extra consent logic needed in the code. This makes the setup GDPR-compliant out of the box.

    Pixel code

    Copy the full code into the Customer Events editor. Remember to replace YOUR_PIXEL_ID.

    Show pixel code ↓
    // ── 1. Load OpenAI Pixel SDK ──────────────────────────────────────
    (function (w, d, s, u) {
      if (w.oaiq) return;
      var q = function () { q.q.push(arguments); };
      q.q = [];
      w.oaiq = q;
      var js = d.createElement(s);
      js.async = true;
      js.src = u;
      var f = d.getElementsByTagName(s)[0];
      f.parentNode.insertBefore(js, f);
    })(window, document, "script", "https://bzrcdn.openai.com/sdk/oaiq.min.js");
    
    oaiq("init", {
      pixelId: "YOUR_PIXEL_ID",
    });
    
    // ── 2. Standard ecommerce events ─────────────────────────────────
    analytics.subscribe("all_standard_events", (event) => {
      switch (event.name) {
    
        case "page_viewed":
          oaiq("measure", "page_viewed", { type: "contents" });
          break;
    
        case "product_viewed":
          var p = event.data && event.data.productVariant;
          oaiq("measure", "contents_viewed", {
            type: "contents",
            contents: [{ id: p && p.sku || p && p.id, name: p && p.product && p.product.title, content_type: "product" }],
          });
          break;
    
        case "product_added_to_cart":
          var line = event.data && event.data.cartLine;
          var m = line && line.merchandise;
          oaiq("measure", "items_added", {
            type: "contents",
            amount: Math.round(((line && line.cost && line.cost.totalAmount && line.cost.totalAmount.amount) || 0) * 100),
            currency: (line && line.cost && line.cost.totalAmount && line.cost.totalAmount.currencyCode) || "EUR",
            contents: [{ id: m && m.sku || m && m.id, name: m && m.product && m.product.title, content_type: "product", quantity: (line && line.quantity) || 1 }],
          });
          break;
    
        case "checkout_started":
          var cs = event.data && event.data.checkout;
          oaiq("measure", "checkout_started", {
            type: "contents",
            amount: Math.round(((cs && cs.totalPrice && cs.totalPrice.amount) || 0) * 100),
            currency: (cs && cs.totalPrice && cs.totalPrice.currencyCode) || "EUR",
            contents: ((cs && cs.lineItems) || []).map(function(i) {
              return { id: (i && i.variant && i.variant.sku) || (i && i.variant && i.variant.id), name: i && i.title, content_type: "product", quantity: i && i.quantity };
            }),
          });
          break;
    
        case "checkout_completed":
          var co = event.data && event.data.checkout;
          oaiq("measure", "order_created", {
            type: "contents",
            amount: Math.round(((co && co.totalPrice && co.totalPrice.amount) || 0) * 100),
            currency: (co && co.totalPrice && co.totalPrice.currencyCode) || "EUR",
            contents: ((co && co.lineItems) || []).map(function(i) {
              return { id: (i && i.variant && i.variant.sku) || (i && i.variant && i.variant.id), name: i && i.title, content_type: "product", quantity: i && i.quantity };
            }),
          });
          break;
      }
    });
    
    // ── 3. Form submissions ───────────────────────────────────────────
    analytics.subscribe("form_submitted", (event) => {
      var element = event.data.element;
      var action = element.action || "";
      var formId = element.id || "";
      var keywords = ["contact", "newsletter", "email", "subscribe"];
      var isLead = keywords.some(function(k) {
        return action.includes(k) || formId.includes(k);
      });
      if (isLead) {
        oaiq("measure", "lead_created", { type: "customer_action" });
      } else {
        oaiq("measure", "custom", { type: "custom" }, { custom_event_name: "form_submitted_other" });
      }
    });
    
    // ── 4. Mailto and tel link clicks ─────────────────────────────────
    analytics.subscribe("clicked", (event) => {
      var href = event.data.element.href || "";
      if (href.startsWith("mailto:")) {
        oaiq("measure", "custom", { type: "custom" }, { custom_event_name: "mailto_click" });
      } else if (href.startsWith("tel:")) {
        oaiq("measure", "custom", { type: "custom" }, { custom_event_name: "tel_click" });
      }
    });

    What events are tracked

    The code tracks eight events automatically:

    • page_viewed – every page load
    • contents_viewed – product page views
    • items_added – add to cart (price, currency, quantity)
    • checkout_started – checkout opened (total, line items)
    • order_created – purchase completed — the primary conversion event
    • lead_created – contact or newsletter form submission
    • mailto_click – email link click (custom event)
    • tel_click – phone number click (custom event)

    Amounts are sent as integers in cents (amount * 100) and the currency code is pulled directly from Shopify's checkout data.

    Testing

    1. Open your store in an incognito window with no ad blockers
    2. Open the Network tab and filter for bzrcdn — requests should appear within a few seconds of triggering events
    3. In OpenAI Ads Manager: Tools → Conversions → Event Stream → Start Polling — events appear with a 5–15 min delay

    If you test in Brave or Firefox with strict tracking protection, the pixel may not fire — this is expected behaviour, not an installation error.

    Campaign optimization: which event to choose

    ChatGPT Ads oCPC campaigns support one standard event per campaign as the optimization target. Choose based on your goal:

    • Ecommerce → order_created
    • Lead generation → lead_created

    All other events are collected for reporting purposes only. mailto_click and tel_click are custom events and cannot be used as oCPC conversion targets.

    Need help with the installation or launching your first ChatGPT Ads campaign? Book a free audit or visit our ChatGPT advertising services page.