Skip to content

Instantly share code, notes, and snippets.

@mattallan
Last active November 7, 2016 01:54
Show Gist options
  • Save mattallan/524758aa2104ebb2cb4b5eefabe24196 to your computer and use it in GitHub Desktop.
Save mattallan/524758aa2104ebb2cb4b5eefabe24196 to your computer and use it in GitHub Desktop.
https://prospress.com facebook pixel code
<?php
/**
* Plugin Name: Prospress.com Facebook Pixel Conversion code
* Description: A plugin to bootup our Facebook Pixels on Prospress.com
* Author: Prospress
* Author URI: http://prospress.com/
* Version: 1.0
*/
/**
* Load Facebook Pixel inside <head> on Home and company blog pages on Prospress.com
*
* Ref: https://developers.facebook.com/docs/facebook-pixel/api-reference
*/
function pp_add_fb_pixel_header() { ?>
<script type="text/javascript">
!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', '1303350309717571' );
fbq('track', 'PageView');
<?php if ( is_page( 'Home' ) ) : ?>
// add pixel tracking to prospress product buttons: https://cloudup.com/cYwKp_PAwjr
$jQuery(document).on( 'click', '.basis-button', function() {
var content = this.attr( 'href' );
fbq( 'trackCustom', 'ProductLinks', {
content_category: 'Prospress Product',
content_type: content
});
});
jQuery(document).on( 'submit', '.contact-form', function() {
fbq( 'trackCustom', 'ContactFormSubmit' ); // Can't think of any data that might be useful to send with this one
});
<?php elseif ( is_single() && ! is_feed() && ! is_archive() ) : ?>
// adds fb pixel tracking to news letter signup form
jQuery(document).on( 'submit', 'form:first', function() { // Can be more specific here but may need to add a class to the newsletter form or modify (wanted to avoid the comment form being tracked)
fbq( 'trackCustom', 'newsletter_signup' );
});
<?php endif; ?>
</script><?php
}
add_action( 'wp_head', 'pp_add_fb_pixel_header' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment