Skip to content

Instantly share code, notes, and snippets.

@panbanda
Last active January 12, 2017 09:26
Show Gist options
  • Save panbanda/a747a6b798e1afa14358007b0e53d8c0 to your computer and use it in GitHub Desktop.
Save panbanda/a747a6b798e1afa14358007b0e53d8c0 to your computer and use it in GitHub Desktop.
Tracking Pixels
<!-- Facebook Pixel Code -->
<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');
fbq('init', '996863543672364'); // Insert your pixel ID here.
fbq('track', 'PageView');
</script>
<noscript><img height="1" width="1"
src="https://www.facebook.com/tr?id=996863543672364&ev=PageView&noscript=1"
/></noscript>
<!-- DO NOT MODIFY -->
<!-- End Facebook Pixel Code -->
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion_async.js"></script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-39633362-1', 'auto');
ga('send', 'pageview');
</script>
/**
* Also need to add AdWords to the proper events on the page. Please ensure the code from google-adwords.html is
* on the page and then using the following codes in related events:
* Explanation: http://stackoverflow.com/questions/27149647/how-to-implement-a-google-adwords-conversion-pixel-using-ajax-on-a-submit-butt
*/
// Page: step 1 ticket list
// Event: next button click
window.google_trackConversion({
google_conversion_id: 973796596,
google_conversion_label: "0va8CLPGlm0Q9Omr0AM",
google_remarketing_only: false
});
// Page: step 2 personal info view
// Event: next button click
window.google_trackConversion({
google_conversion_id: 973796596,
google_conversion_label: "le5tCIzNm20Q9Omr0AM",
google_remarketing_only: false
});
// Page: step 3 final step
// Event: checkout button click
window.google_trackConversion({
google_conversion_id: 973796596,
google_conversion_label: "3GGfCM3xgm0Q9Omr0AM",
google_remarketing_only: false
});
// Page: payment
// Event: pay button click
window.google_trackConversion({
google_conversion_id: 973796596,
google_conversion_label: "pWDdCMHYm20Q9Omr0AM",
google_conversion_value: 150, // Price of ticket
google_conversion_currency: 'USD',
google_remarketing_only: false
});
// For example, if you're using some sort of click event we need this in the callback
$('.element').click(function() {
window.google_trackConversion({
google_conversion_id: 973796596,
google_conversion_label: "le5tCIzNm20Q9Omr0AM",
google_remarketing_only: false
});
});
/**
* Per the documentation (https://www.facebook.com/business/help/952192354843755) we need to
* send the proper events for proper pages so we can track things clearly. After the facebook & google
* pixels has been installed on each page we need the following events sent:
*/
// Viewing a ticket to purchase (like when we do the access-token link to your site to view ticket)
fbq('track', 'ViewContent');
ga('send', 'ViewContent');
// On the page where users fill out the information
fbq('track', 'InitiateCheckout');
ga('send', 'InitiateCheckout');
// When filling out the payment information
fbq('track', 'AddPaymentInfo');
ga('send', 'AddPaymentInfo');
// When the purchase "SUCCESS" is shown and user has completed purchase
fbq('track', 'Purchase');
ga('send', 'Purchase');
// For example, if you're using some sort of ajax event we need this in the callback
$.getJSON(..., function(data) {
if (data.success) {
fbq('track', 'AddPaymentInfo');
ga('send', 'AddPaymentInfo');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment