Skip to content

Instantly share code, notes, and snippets.

@mattallan
Last active November 7, 2016 01:57
Show Gist options
  • Save mattallan/c39a3e3c897869c65609418dfe5cee87 to your computer and use it in GitHub Desktop.
Save mattallan/c39a3e3c897869c65609418dfe5cee87 to your computer and use it in GitHub Desktop.
Small Woorld Facebook Pixel Code
<?php
/**
* Plugin Name: Small Woorld Facebook Pixel Conversion code
* Description: A plugin to bootup our Facebook Pixels on Prospress.com
* Author: Prospress
* Author URI: https://smallwoorld.com/
* Version: 1.0
*/
/**
* Load Facebook Pixel inside <head> on all blog pages on smallwoorld.com
*
* Tracks people clicking the following signup button: https://cl.ly/2M1e25363C0u
* Ref: https://developers.facebook.com/docs/facebook-pixel/api-reference
*/
function sw_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', '983754648414193' );
fbq( 'track', 'PageView' );
<?php if ( is_single() && ! is_feed() && ! is_archive() ) : ?>
jQuery(document).on( 'submit', '.mc4wp-form', function() { // Can probably be more specific by using $('[data-name="Small Woorld Sign-up Form"]') - not necessary though
fbq( 'trackCustom', 'SmallWoorldSignUp' );
});
<?php endif; ?>
</script><?php
}
add_action( 'wp_head', 'sw_add_fb_pixel_header' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment