Created
July 27, 2023 16:57
-
-
Save ashawkat/5201972db199224ce06d21216aa2fbb5 to your computer and use it in GitHub Desktop.
Pixel events set on CMS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
!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'); | |
// replace YOUR_PIXEL_ID with the pixel ID provided by third-party | |
fbq('init', YOUR_PIXEL_ID); | |
// integrate third-party pixel tracking | |
analytics.subscribe("page_viewed", event => { | |
fbq('track', 'PageView'); | |
}); | |
analytics.subscribe("product_viewed", async (event) => { | |
fbq('track', 'ViewContent', { | |
content_ids: [event.data.productVariant.id], | |
content_name: event.data.productVariant.title, | |
currency: event.data.productVariant.price.currencyCode, | |
value: event.data.productVariant.price.amount, | |
}); | |
}); | |
analytics.subscribe("search_submitted", async (event) => { | |
fbq('track', 'Search', { | |
search_string: event.searchResult.query | |
}); | |
}); | |
analytics.subscribe("product_added_to_cart", async (event) => { | |
fbq('track', 'AddToCart', { | |
content_ids: [event.data.cartLine.merchandise.productVariant.id], | |
content_name: event.data.cartLine.merchandise.productVariant.title, | |
currency: event.data.cartLine.merchandise.productVariant.price.currencyCode, | |
value: event.data.cartLine.merchandise.productVariant.price.amount, | |
}); | |
}); | |
analytics.subscribe("payment_info_submitted", async (event) => { | |
fbq('track', 'AddPaymentInfo'); | |
}); | |
analytics.subscribe("checkout_started", async (event) => { | |
fbq('track', 'InitiateCheckout'); | |
}); | |
analytics.subscribe("checkout_completed", async (event) => { | |
fbq('track', 'Purchase', { | |
currency: event.checkout.currencyCode, | |
value: event.checkout.totalPrice.amount, | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment