This repository was archived by the owner on Aug 24, 2020. It is now read-only.
forked from aickowicz/mixpanel-wordpress
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpage.php
More file actions
137 lines (120 loc) · 3.67 KB
/
page.php
File metadata and controls
137 lines (120 loc) · 3.67 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?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 (empty($event_label)) {
return false;
}
$settings = (array) get_option( 'mixpanel_settings' );
if (!isset($settings['token_id'])) {
self::no_mixpanel_token_found();
return false;
}
$event_label = self::get_post_event_label();
if (!empty($event_label)) {
echo "<script type='text/javascript'>
mixpanel.register_once({
'First page': document.title,
'First page visit date': new Date().toISOString()
});
mixpanel.track(\"$event_label\", {
'Page Name': document.title,
'Page Url': window.location.pathname
});
</script>";
}
/*
* START STATIC PAGE MIXPANEL JS
*/
?>
<script type='text/javascript'>
jQuery( document ).ready(function() {
jQuery('#site-header .sign-in button').click(function() {
var signInCount = mixpanel.get_property('Sign In Count') || 0;
signInCount++;
mixpanel.register({
'Sign In Count': signInCount,
'Last Sign In Date': new Date().toISOString()
});
mixpanel.track('Sign In');
});
jQuery('#site-wrapper a[href|="/demo"]').click(function(event) {
mixpanel.track('Book a Demo', {
'source page': document.title,
'button location': event.currentTarget.id
});
});
jQuery('#site-header a[href|="/demo"]').click(function(event) {
mixpanel.track('Book a Demo', {
'source page': document.title,
'button location': event.currentTarget.id
});
});
jQuery('#site-footer a[href|="/demo"]').click(function(event) {
mixpanel.track('Book a Demo', {
'button location': 'Footer'
});
});
jQuery('a[href|="/support"]').click(function(event) {
mixpanel.track('Support Clicked', {
'Topic': jQuery(event.currentTarget).text()
});
});
jQuery('ul.download a, a[href|="/app-downloads"]').click(function(event) {
mixpanel.register({'App store': event.currentTarget.id});
mixpanel.track('Download App');
});
});
</script>
<?php
/*
* END STATIC PAGE MIXPANEL JS
*/
return true;
}
/**
* Adds the Javascript necessary to start tracking via MixPanel.
* this gets added to the <head> section usually.
*
* @return [type] [description]
*/
function insert_tracker()
{
$settings = (array) get_option( 'mixpanel_settings' );
if(!isset($settings['token_id'])) {
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 -->";
}
}
// Enqueue the jQuery UI Scrollable plugin, which is required for
// the custom MCE editor to work.
function jquery_ui_scrollable() {
wp_enqueue_script('jquery-ui-scrollable', plugins_url("js/jquery-ui-scrollable.min.js", __FILE__), array('jquery-ui'), '0.1.1');
wp_enqueue_script('jquery-ui', "//code.jquery.com/ui/1.11.4/jquery-ui.min.js", array(), '1.11.4');
}
add_action('wp_enqueue_scripts', 'jquery_ui_scrollable');
?>