-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpage.php
More file actions
83 lines (75 loc) · 2.25 KB
/
page.php
File metadata and controls
83 lines (75 loc) · 2.25 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
<?php
add_action('wp_head', array('uTu', 'insert_tracker'));
add_action('wp_footer', array('uTu', 'insert_event'));
class uTu {
/**
* Gets the value of the key utu_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, 'utu_event_label', true );
}
static function get_post_title()
{
global $post;
return $post->post_title;
}
/**
* Inserts the value for the utu.track() API Call
* @return boolean technically this should be html..
*/
function insert_event() {
$settings = (array) get_option( 'utu_settings' );
$event_label = self::get_post_event_label();
$my_title = self::get_post_title();
echo "<script>console.log( 'trying to set event: " . $event_label . " (EOL)' );</script>";
if (!empty($event_label)) {
echo
"<script type='text/javascript'>
utu.track(\"$event_label\", {
'Post Name': \"$my_title\",
'Page Url': window.location.pathname,
});
</script>";
}
echo "<script>console.log( 'set event: " . $event_label . " (EOL)' );</script>";
?>
<input type="button" class="trackCTA" />
<script type='text/javascript'>
var ctaClicks = window.document.getElementsByClassName("trackCTA");
[].forEach.call(ctaClicks, function (cta) {
cta.addEventListener("click", function(event) {
utu.track('wp > site', {});
});
});
</script>
<?php
/*
* END STATIC PAGE UTU JS
*/
return true;
}
/**
* Adds the Javascript necessary to start tracking via uTu.
* This gets added to the <head> section.
*
* @return [type] [description]
*/
static function insert_tracker() {
$settings = get_option('utu_settings');
if (!isset($settings['token_id'])) {
self::no_utu_token_found();
return false;
}
require_once dirname(__FILE__) . '/utu-wp-js.php';
return true;
}
static function no_utu_token_found()
{
echo "<!-- No uTu Token Defined -->";
}
}
?>