-
Notifications
You must be signed in to change notification settings - Fork 23
/
page.php
69 lines (51 loc) · 1.41 KB
/
page.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?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;
hi;
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.register_once({ 'first_referrer': document.referrer });
mixpanel.track(\"$event_label\", {'referrer': document.referrer });
</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 -->";
}
}
?>