// Quizproof → Google Analytics 4 and the Meta Pixel. // Paste into Shopify admin › Settings › Customer events › Add custom pixel. Set the IDs below (leave one empty // to skip it), Save, then Connect. Shopify runs this only for visitors whose consent allows its permission // (set the pixel's Customer privacy to "Required" with Analytics, and Marketing if you use the Meta Pixel). // // Quizproof publishes these events (ids only, never answers or contact details): // quizproof:quiz_viewed {quiz, sessionId} // quizproof:quiz_started {quiz, sessionId} // quizproof:quiz_completed {quiz, version, sessionId, productIds[]} // quizproof:add_to_cart {sessionId, variantIds[]} // quizproof:optin {sessionId} // GA4 receives them as quizproof_quiz_viewed, quizproof_quiz_started, …; Meta as custom events // QuizproofQuizViewed, QuizproofQuizStarted, …. Shopify's own standard events (page views, AddToCart, // Purchase) are not repeated here. const GA4_MEASUREMENT_ID = ""; // e.g. "G-ABC123XYZ9" const META_PIXEL_ID = ""; // e.g. "123456789012345" if (GA4_MEASUREMENT_ID) { const s = document.createElement("script"); s.async = true; s.src = "https://www.googletagmanager.com/gtag/js?id=" + encodeURIComponent(GA4_MEASUREMENT_ID); document.head.appendChild(s); window.dataLayer = window.dataLayer || []; window.gtag = function () { window.dataLayer.push(arguments); }; window.gtag("js", new Date()); window.gtag("config", GA4_MEASUREMENT_ID, { send_page_view: false }); } if (META_PIXEL_ID) { // Meta's base code (fbevents.js), without its PageView: Shopify's own Meta integration sends page views. !(function (f, b, e, v, n, t, s) { if (f.fbq) return; n = f.fbq = function () { n.callMethod ? n.callMethod.apply(n, arguments) : n.queue.push(arguments); }; if (!f._fbq) f._fbq = n; n.push = n; n.loaded = !0; n.version = "2.0"; n.queue = []; t = b.createElement(e); t.async = !0; t.src = v; s = b.getElementsByTagName(e)[0]; s.parentNode.insertBefore(t, s); })(window, document, "script", "https://connect.facebook.net/en_US/fbevents.js"); window.fbq("init", META_PIXEL_ID); } const PREFIX = "quizproof:"; analytics.subscribe("all_custom_events", (event) => { if (typeof event.name !== "string" || !event.name.startsWith(PREFIX)) return; const name = event.name.slice(PREFIX.length); const d = event.customData || {}; const ids = d.productIds || d.variantIds || []; const params = { quiz: d.quiz, quiz_version: d.version, quiz_session: d.sessionId, item_ids: ids.join(",") }; if (GA4_MEASUREMENT_ID && window.gtag) { window.gtag("event", "quizproof_" + name, Object.assign({}, params, { items: ids.map((id) => ({ item_id: id })) })); } if (META_PIXEL_ID && window.fbq) { const custom = "Quizproof" + name.split("_").map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(""); window.fbq("trackCustom", custom, Object.assign({}, params, { content_ids: ids })); } });