Permalink
Browse files

initial prototype hat's working for the homepage

Initial draft and commit of the plugin.
  • Loading branch information...
0 parents commit 31d80e6679cb0b50a61c3e8e10ca3fe01ffc975c Vid Luther committed May 24, 2012
Showing with 148 additions and 0 deletions.
  1. +18 −0 Readme.txt
  2. +4 −0 eventjs.php
  3. +30 −0 meta-box.php
  4. +17 −0 mixpanel.php
  5. +12 −0 mixpaneljs.php
  6. +67 −0 page.php
@@ -0,0 +1,18 @@
+This is the MixPanel Plugin for WordPress.
+
+To install the plugin, either upload the .zip file using the plugin installer in your wp-admin, or
+SFTP the files over to your wp-content/plugins/ directory.
+
+Configuration Options
+
+There are some variables that are necessary to make the plugin do it's thing.
+
+MIXPANEL_TOKEN: This is the token for your specific project.
+MIXPANEL_DEBUG: If your site is in development mode, you can turn this on and see debug messages in your Firebug Console
+MIXPANEL_SUBDOMAIN_COOKIE: Make this true if you have MixPanel on two sites with the same token. Like blog.domain.com, app.domain.com
+
+How does it work?
+
+On every page in WordPress, you'll see an option panel for MixPanel Event Label. Whatever value you put in this label, will
+show up as an event in MixPanel.
+
@@ -0,0 +1,4 @@
+
+<script type="text/javascript">
+mixpanel.track("<?php echo $event_label;?>");
+</script>
@@ -0,0 +1,30 @@
+<?php
+
+add_action( 'admin_menu', 'mixpanel_create_meta_box' );
+add_action( 'save_post', 'mixpanel_update_event_label' );
+
+function mixpanel_create_meta_box(){
+ if( function_exists('add_meta_box') ){
+ add_meta_box( 'mixpanel-event-label', 'MixPanel Event Label', 'mixpanel_event_box', 'page' );
+ }
+}
+
+function mixpanel_event_box(){
+ global $post;
+ $mixpanel_event_label = get_post_meta( $post->ID, 'mixpanel_event_label', true );
+ ?>
+ <table class="form_table">
+ <tr>
+ <th width="30%"><label for="mixpanel_event_label">MixPanel Event Name</label></th>
+ <td width="70%"><input type="text" size="60" name="mixpanel_event_label" value="<?php echo $mixpanel_event_label; ?>" /></td>
+ </tr>
+ </table>
+ <?php
+}
+
+function mixpanel_update_event_label( $post_id ){
+ if( isset($_POST['mixpanel_event_label']) ){
+ update_post_meta( $post_id, 'mixpanel_event_label', $_POST['mixpanel_event_label'] );
+ }
+}
+?>
@@ -0,0 +1,17 @@
+<?php
+/*
+Plugin Name: MixPanel for WordPress
+Plugin URI: http://zippykid.com/
+Description: A relatively easy way to integrate MixPanel with your WordPress site
+Author: Vid Luther <vid@zippykid.com>
+Version: 0.1
+Author URI: http://zippykid.com/
+*/
+
+if( is_admin() ){
+ require_once dirname( __FILE__ ) . '/meta-box.php';
+} else {
+ require_once dirname( __FILE__ ) . '/page.php';
+}
+
+?>
@@ -0,0 +1,12 @@
+<!-- start Mixpanel -->
+<script type="text/javascript">(function(d,c){var a,b,g,e;a=d.createElement("script");a.type="text/javascript";a.async=!0;a.src=("https:"===d.location.protocol?"https:":"http:")+'//api.mixpanel.com/site_media/js/api/mixpanel.2.js';b=d.getElementsByTagName("script")[0];b.parentNode.insertBefore(a,b);c._i=[];c.init=function(a,d,f){var b=c;"undefined"!==typeof f?b=c[f]=[]:f="mixpanel";g="disable track track_pageview track_links track_forms register register_once unregister identify name_tag set_config".split(" ");
+for(e=0;e<g.length;e++)(function(a){b[a]=function(){b.push([a].concat(Array.prototype.slice.call(arguments,0)))}})(g[e]);c._i.push([a,d,f])};window.mixpanel=c})(document,[]);
+mixpanel.init("<?php echo MIXPANEL_TOKEN; ?>");</script>
+
+<script type="text/javascript">
+mixpanel.set_config({
+ cross_subdomain_cookie: <?php if (MIXPANEL_SUBDOMAIN_COOKIE === TRUE) { echo 'true'; } else { echo 'false'; } ?>,
+ debug: <?php if (MIXPANEL_DEBUG === TRUE) { echo 'true'; } else { echo 'false'; } ?>
+});
+</script>
+<!-- end Mixpanel -->
@@ -0,0 +1,67 @@
+<?php
+add_action( 'wp_head', array('MixPanel','insert_tracker' ));
+add_action( 'wp_footer', array('MixPanel','insert_event' ));
+
+
+
+class MixPanel {
+
+ /**
+ * Gets the value of the key mixpanel_event_label for this specific Post
+ *
+ * @return string The value of the meta box set on the page
+ */
+ static function get_post_event_label()
+ {
+ global $post;
+ return get_post_meta( $post->ID, 'mixpanel_event_label', true );
+ }
+
+ /**
+ * Inserts the value for the mixpanel.track() API Call
+ * @return boolean technically this should be html..
+ */
+ function insert_event()
+ {
+ $event_label = self::get_post_event_label();
+
+ if(!defined('MIXPANEL_TOKEN')) {
+ self::no_mixpanel_token_found();
+ return false;
+ }
+ echo "<script type='text/javascript'>
+ mixpanel.track(\"$event_label\");
+ </script> ";
+
+
+
+ return true;
+ }
+
+
+ /**
+ * Adds the Javascript necessary to start tracking via MixPanel.
+ * @return [type] [description]
+ */
+ function insert_tracker()
+ {
+
+ if(!defined('MIXPANEL_TOKEN')) {
+ self::no_mixpanel_token_found();
+ return false;
+ }
+ require_once dirname(__FILE__) . '/mixpaneljs.php';
+
+
+ return true;
+ }
+
+ static function no_mixpanel_token_found()
+ {
+ echo "<!-- No MixPanel Token Defined -->";
+ }
+
+}
+
+
+?>

0 comments on commit 31d80e6

Please sign in to comment.