Version Description
Allow tokens in the custom variables
Download this release
Release Info
Developer | aaroncampbell |
Plugin | WP Google Analytics |
Version | 1.4.0 |
Comparing to | |
See all releases |
Code changes from version 1.3.1 to 1.4.0
- languages/wp-google-analytics.pot +88 -22
- readme.txt +33 -9
- wp-google-analytics.php +187 -4
languages/wp-google-analytics.pot
CHANGED
@@ -2,9 +2,9 @@
|
|
2 |
# This file is distributed under the same license as the WP Google Analytics package.
|
3 |
msgid ""
|
4 |
msgstr ""
|
5 |
-
"Project-Id-Version: WP Google Analytics 1.
|
6 |
"Report-Msgid-Bugs-To: http://wordpress.org/tag/wp-google-analytics\n"
|
7 |
-
"POT-Creation-Date: 2012-10-
|
8 |
"MIME-Version: 1.0\n"
|
9 |
"Content-Type: text/plain; charset=UTF-8\n"
|
10 |
"Content-Transfer-Encoding: 8bit\n"
|
@@ -12,87 +12,153 @@ msgstr ""
|
|
12 |
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
13 |
"Language-Team: LANGUAGE <LL@li.org>\n"
|
14 |
|
15 |
-
#: wp-google-analytics.php:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
msgid "Google Analytics"
|
17 |
msgstr ""
|
18 |
|
19 |
-
#: wp-google-analytics.php:
|
20 |
msgid "Google Analytics tracking ID:"
|
21 |
msgstr ""
|
22 |
|
23 |
-
#: wp-google-analytics.php:
|
24 |
msgid "Additional items to log:"
|
25 |
msgstr ""
|
26 |
|
27 |
-
#: wp-google-analytics.php:
|
28 |
msgid "Visits to ignore:"
|
29 |
msgstr ""
|
30 |
|
31 |
-
#: wp-google-analytics.php:
|
32 |
msgid "Custom variables:"
|
33 |
msgstr ""
|
34 |
|
35 |
-
#: wp-google-analytics.php:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
msgid ""
|
37 |
"Paste your Google Analytics tracking ID (e.g. \"UA-XXXXXX-X\") into the "
|
38 |
"field."
|
39 |
msgstr ""
|
40 |
|
41 |
-
#: wp-google-analytics.php:
|
42 |
msgid "Log 404 errors as events"
|
43 |
msgstr ""
|
44 |
|
45 |
-
#: wp-google-analytics.php:
|
46 |
msgid ""
|
47 |
"Log searches as /search/{search}?referrer={referrer} (<a href=\"%s"
|
48 |
"\">deprecated</a>)"
|
49 |
msgstr ""
|
50 |
|
51 |
-
#: wp-google-analytics.php:
|
52 |
msgid "Log outgoing links as events"
|
53 |
msgstr ""
|
54 |
|
55 |
-
#: wp-google-analytics.php:
|
56 |
msgid "Default"
|
57 |
msgstr ""
|
58 |
|
59 |
-
#: wp-google-analytics.php:
|
60 |
msgid "Visitor"
|
61 |
msgstr ""
|
62 |
|
63 |
-
#: wp-google-analytics.php:
|
64 |
msgid "Session"
|
65 |
msgstr ""
|
66 |
|
67 |
-
#: wp-google-analytics.php:
|
68 |
msgid "Page"
|
69 |
msgstr ""
|
70 |
|
71 |
-
#: wp-google-analytics.php:
|
72 |
msgid "Name"
|
73 |
msgstr ""
|
74 |
|
75 |
-
#: wp-google-analytics.php:
|
76 |
msgid "Value"
|
77 |
msgstr ""
|
78 |
|
79 |
-
#: wp-google-analytics.php:
|
80 |
msgid "Scope"
|
81 |
msgstr ""
|
82 |
|
83 |
-
#: wp-google-analytics.php:
|
84 |
msgid "Do not log anything in the admin area"
|
85 |
msgstr ""
|
86 |
|
87 |
-
#: wp-google-analytics.php:
|
88 |
msgid "Do not log %s when logged in"
|
89 |
msgstr ""
|
90 |
|
91 |
-
#: wp-google-analytics.php:
|
92 |
msgid "Google Analytics Options"
|
93 |
msgstr ""
|
94 |
|
95 |
-
#: wp-google-analytics.php:
|
96 |
msgid "Update Options"
|
97 |
msgstr ""
|
98 |
|
2 |
# This file is distributed under the same license as the WP Google Analytics package.
|
3 |
msgid ""
|
4 |
msgstr ""
|
5 |
+
"Project-Id-Version: WP Google Analytics 1.4.0\n"
|
6 |
"Report-Msgid-Bugs-To: http://wordpress.org/tag/wp-google-analytics\n"
|
7 |
+
"POT-Creation-Date: 2012-10-05 21:16:58+00:00\n"
|
8 |
"MIME-Version: 1.0\n"
|
9 |
"Content-Type: text/plain; charset=UTF-8\n"
|
10 |
"Content-Transfer-Encoding: 8bit\n"
|
12 |
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
13 |
"Language-Team: LANGUAGE <LL@li.org>\n"
|
14 |
|
15 |
+
#: wp-google-analytics.php:78
|
16 |
+
msgid "Post author for current view"
|
17 |
+
msgstr ""
|
18 |
+
|
19 |
+
#: wp-google-analytics.php:79
|
20 |
+
msgid "Post author's display name"
|
21 |
+
msgstr ""
|
22 |
+
|
23 |
+
#: wp-google-analytics.php:94
|
24 |
+
msgid "Categories assigned to a post"
|
25 |
+
msgstr ""
|
26 |
+
|
27 |
+
#: wp-google-analytics.php:95
|
28 |
+
msgid "Category names in a commma-separated list"
|
29 |
+
msgstr ""
|
30 |
+
|
31 |
+
#: wp-google-analytics.php:109
|
32 |
+
msgid "Which view the visitor is on"
|
33 |
+
msgstr ""
|
34 |
+
|
35 |
+
#: wp-google-analytics.php:110
|
36 |
+
msgid "Samples: 'home', 'category', 'post', 'author'"
|
37 |
+
msgstr ""
|
38 |
+
|
39 |
+
#: wp-google-analytics.php:116
|
40 |
+
msgid "Publication date for the current view"
|
41 |
+
msgstr ""
|
42 |
+
|
43 |
+
#: wp-google-analytics.php:117
|
44 |
+
msgid "Format specified by 'Date Format' in Settings -> General"
|
45 |
+
msgstr ""
|
46 |
+
|
47 |
+
#: wp-google-analytics.php:132
|
48 |
+
msgid "Tags assigned to a post"
|
49 |
+
msgstr ""
|
50 |
+
|
51 |
+
#: wp-google-analytics.php:133
|
52 |
+
msgid "Tag names in a commma-separated list"
|
53 |
+
msgstr ""
|
54 |
+
|
55 |
+
#: wp-google-analytics.php:148
|
56 |
+
msgid "Whether or not the viewer is logged in"
|
57 |
+
msgstr ""
|
58 |
+
|
59 |
+
#: wp-google-analytics.php:149
|
60 |
+
msgid "'true' or 'false'"
|
61 |
+
msgstr ""
|
62 |
+
|
63 |
+
#: wp-google-analytics.php:160
|
64 |
msgid "Google Analytics"
|
65 |
msgstr ""
|
66 |
|
67 |
+
#: wp-google-analytics.php:171
|
68 |
msgid "Google Analytics tracking ID:"
|
69 |
msgstr ""
|
70 |
|
71 |
+
#: wp-google-analytics.php:172
|
72 |
msgid "Additional items to log:"
|
73 |
msgstr ""
|
74 |
|
75 |
+
#: wp-google-analytics.php:173
|
76 |
msgid "Visits to ignore:"
|
77 |
msgstr ""
|
78 |
|
79 |
+
#: wp-google-analytics.php:174
|
80 |
msgid "Custom variables:"
|
81 |
msgstr ""
|
82 |
|
83 |
+
#: wp-google-analytics.php:183
|
84 |
+
msgid ""
|
85 |
+
"Use tokens in your custom variables to make your fields dynamic based on "
|
86 |
+
"context. Here are some of the tokens you can use:"
|
87 |
+
msgstr ""
|
88 |
+
|
89 |
+
#: wp-google-analytics.php:185
|
90 |
+
msgid "Token"
|
91 |
+
msgstr ""
|
92 |
+
|
93 |
+
#: wp-google-analytics.php:185
|
94 |
+
msgid "Description"
|
95 |
+
msgstr ""
|
96 |
+
|
97 |
+
#: wp-google-analytics.php:185
|
98 |
+
msgid "Return value"
|
99 |
+
msgstr ""
|
100 |
+
|
101 |
+
#: wp-google-analytics.php:199
|
102 |
msgid ""
|
103 |
"Paste your Google Analytics tracking ID (e.g. \"UA-XXXXXX-X\") into the "
|
104 |
"field."
|
105 |
msgstr ""
|
106 |
|
107 |
+
#: wp-google-analytics.php:207
|
108 |
msgid "Log 404 errors as events"
|
109 |
msgstr ""
|
110 |
|
111 |
+
#: wp-google-analytics.php:208
|
112 |
msgid ""
|
113 |
"Log searches as /search/{search}?referrer={referrer} (<a href=\"%s"
|
114 |
"\">deprecated</a>)"
|
115 |
msgstr ""
|
116 |
|
117 |
+
#: wp-google-analytics.php:209
|
118 |
msgid "Log outgoing links as events"
|
119 |
msgstr ""
|
120 |
|
121 |
+
#: wp-google-analytics.php:227
|
122 |
msgid "Default"
|
123 |
msgstr ""
|
124 |
|
125 |
+
#: wp-google-analytics.php:228
|
126 |
msgid "Visitor"
|
127 |
msgstr ""
|
128 |
|
129 |
+
#: wp-google-analytics.php:229
|
130 |
msgid "Session"
|
131 |
msgstr ""
|
132 |
|
133 |
+
#: wp-google-analytics.php:230
|
134 |
msgid "Page"
|
135 |
msgstr ""
|
136 |
|
137 |
+
#: wp-google-analytics.php:236
|
138 |
msgid "Name"
|
139 |
msgstr ""
|
140 |
|
141 |
+
#: wp-google-analytics.php:239
|
142 |
msgid "Value"
|
143 |
msgstr ""
|
144 |
|
145 |
+
#: wp-google-analytics.php:242
|
146 |
msgid "Scope"
|
147 |
msgstr ""
|
148 |
|
149 |
+
#: wp-google-analytics.php:256
|
150 |
msgid "Do not log anything in the admin area"
|
151 |
msgstr ""
|
152 |
|
153 |
+
#: wp-google-analytics.php:260
|
154 |
msgid "Do not log %s when logged in"
|
155 |
msgstr ""
|
156 |
|
157 |
+
#: wp-google-analytics.php:321
|
158 |
msgid "Google Analytics Options"
|
159 |
msgstr ""
|
160 |
|
161 |
+
#: wp-google-analytics.php:326
|
162 |
msgid "Update Options"
|
163 |
msgstr ""
|
164 |
|
readme.txt
CHANGED
@@ -1,23 +1,36 @@
|
|
1 |
=== WP Google Analytics ===
|
2 |
-
Contributors: aaroncampbell
|
3 |
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=CLXNQ3DVK6M48
|
4 |
Tags: analytics, google, google analytics
|
5 |
Requires at least: 3.1
|
6 |
Tested up to: 3.5
|
7 |
-
Stable tag: 1.
|
8 |
|
9 |
Lets you use <a href="http://analytics.google.com">Google Analytics</a> to track your WordPress site statistics
|
10 |
|
11 |
== Description ==
|
12 |
|
13 |
-
|
14 |
-
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
*
|
19 |
-
*
|
20 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
== Installation ==
|
23 |
|
@@ -40,6 +53,11 @@ removed. To track searches in Google Analytics follow this
|
|
40 |
<a href="http://support.google.com/analytics/bin/answer.py?hl=en&answer=1012264">Google support article</a>.
|
41 |
WordPress uses 's' as the query parameter.
|
42 |
|
|
|
|
|
|
|
|
|
|
|
43 |
= Can't I just paste the Google Analytics code into my template file? =
|
44 |
|
45 |
Absolutely, however in order to get a better idea of what is going on with your
|
@@ -49,6 +67,9 @@ easily do all these things.
|
|
49 |
|
50 |
== Upgrade Notice ==
|
51 |
|
|
|
|
|
|
|
52 |
= 1.3.1 =
|
53 |
Fix for custom variables not being tracked
|
54 |
|
@@ -57,6 +78,9 @@ Move to using events for tracking 404s and outgoing links and add support for cu
|
|
57 |
|
58 |
== Changelog ==
|
59 |
|
|
|
|
|
|
|
60 |
= 1.3.1 =
|
61 |
* Fixed custom variables not being tracked
|
62 |
|
1 |
=== WP Google Analytics ===
|
2 |
+
Contributors: range, PeteMall, saracannon, aaroncampbell
|
3 |
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=CLXNQ3DVK6M48
|
4 |
Tags: analytics, google, google analytics
|
5 |
Requires at least: 3.1
|
6 |
Tested up to: 3.5
|
7 |
+
Stable tag: 1.4.0
|
8 |
|
9 |
Lets you use <a href="http://analytics.google.com">Google Analytics</a> to track your WordPress site statistics
|
10 |
|
11 |
== Description ==
|
12 |
|
13 |
+
WP Google Analytics makes it easy to track your site's usage, with lots of
|
14 |
+
helpful additional data.
|
15 |
|
16 |
+
Features:
|
17 |
+
|
18 |
+
* Uses Google's asynchronous tracking method which is faster and more reliable.
|
19 |
+
* Automatically tracks site speed
|
20 |
+
* Option to log outgoing links as events
|
21 |
+
* Option to log 404 errors as events
|
22 |
+
* Use custom variables in Google Analytics to track additional data on pageviews including:
|
23 |
+
* Author
|
24 |
+
* Categories
|
25 |
+
* Tags
|
26 |
+
* Context (such as home, category, post, author, etc)
|
27 |
+
* Date
|
28 |
+
* Logged in
|
29 |
+
* Anything - Use the built-in filter to add your own!
|
30 |
+
* Allows you to ignore any user roles (administrators, editors, authors, etc)
|
31 |
+
|
32 |
+
<a href="http://bluedogwebservices.com/wordpress-plugin/wp-google-analytics/">WP Google Analytics</a>
|
33 |
+
Brought to you by <a href="http://ran.ge/" title="WordPress Development">Ran.ge</a>
|
34 |
|
35 |
== Installation ==
|
36 |
|
53 |
<a href="http://support.google.com/analytics/bin/answer.py?hl=en&answer=1012264">Google support article</a>.
|
54 |
WordPress uses 's' as the query parameter.
|
55 |
|
56 |
+
= What tokens are support for custom variables? =
|
57 |
+
|
58 |
+
All the built-in tokens are described on the settings page. You can also add
|
59 |
+
your own using the 'wga_tokens' filter.
|
60 |
+
|
61 |
= Can't I just paste the Google Analytics code into my template file? =
|
62 |
|
63 |
Absolutely, however in order to get a better idea of what is going on with your
|
67 |
|
68 |
== Upgrade Notice ==
|
69 |
|
70 |
+
= 1.4.0 =
|
71 |
+
Allow tokens in the custom variables
|
72 |
+
|
73 |
= 1.3.1 =
|
74 |
Fix for custom variables not being tracked
|
75 |
|
78 |
|
79 |
== Changelog ==
|
80 |
|
81 |
+
= 1.4.0 =
|
82 |
+
* Support for tokens in custom variables
|
83 |
+
|
84 |
= 1.3.1 =
|
85 |
* Fixed custom variables not being tracked
|
86 |
|
wp-google-analytics.php
CHANGED
@@ -3,14 +3,14 @@
|
|
3 |
* Plugin Name: WP Google Analytics
|
4 |
* Plugin URI: http://bluedogwebservices.com/wordpress-plugin/wp-google-analytics/
|
5 |
* Description: Lets you use <a href="http://analytics.google.com">Google Analytics</a> to track your WordPress site statistics
|
6 |
-
* Version: 1.
|
7 |
* Author: Aaron D. Campbell
|
8 |
* Author URI: http://ran.ge/
|
9 |
* License: GPLv2 or later
|
10 |
* Text Domain: wp-google-analytics
|
11 |
*/
|
12 |
|
13 |
-
define('WGA_VERSION', '1.
|
14 |
|
15 |
/* Copyright 2006 Aaron D. Campbell (email : wp_plugins@xavisys.com)
|
16 |
|
@@ -43,16 +43,19 @@ class wpGoogleAnalytics {
|
|
43 |
|
44 |
static $page_slug = 'wp-google-analytics';
|
45 |
|
|
|
|
|
46 |
/**
|
47 |
* This is our constructor, which is private to force the use of get_instance()
|
48 |
* @return void
|
49 |
*/
|
50 |
private function __construct() {
|
51 |
-
add_filter( 'init', array( $this, '
|
52 |
add_action( 'admin_init', array( $this, 'admin_init' ) );
|
53 |
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
|
54 |
add_action( 'get_footer', array( $this, 'insert_code' ) );
|
55 |
add_action( 'wp_enqueue_scripts', array( $this, 'track_outgoing' ) );
|
|
|
56 |
}
|
57 |
|
58 |
/**
|
@@ -65,8 +68,90 @@ class wpGoogleAnalytics {
|
|
65 |
return self::$instance;
|
66 |
}
|
67 |
|
68 |
-
public function
|
69 |
load_plugin_textdomain( 'jetpack', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
}
|
71 |
|
72 |
/**
|
@@ -80,6 +165,7 @@ class wpGoogleAnalytics {
|
|
80 |
* Register our settings
|
81 |
*/
|
82 |
public function admin_init() {
|
|
|
83 |
register_setting( 'wga', 'wga', array( $this, 'sanitize_general_options' ) );
|
84 |
|
85 |
add_settings_section( 'wga_general', false, '__return_false', 'wga' );
|
@@ -93,6 +179,23 @@ class wpGoogleAnalytics {
|
|
93 |
* Where the user adds their Google Analytics code
|
94 |
*/
|
95 |
public function field_code() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
echo '<input name="wga[code]" id="wga-code" type="text" value="' . esc_attr( $this->_get_options( 'code' ) ) . '" />';
|
97 |
echo '<p class="description">' . __( 'Paste your Google Analytics tracking ID (e.g. "UA-XXXXXX-X") into the field.', 'wp-google-analytics' ) . '</p>';
|
98 |
}
|
@@ -118,6 +221,7 @@ class wpGoogleAnalytics {
|
|
118 |
* Define custom variables to be included in your tracking code
|
119 |
*/
|
120 |
public function field_custom_variables() {
|
|
|
121 |
$custom_vars = $this->_get_options( 'custom_vars' );
|
122 |
|
123 |
$scope_options = array(
|
@@ -145,6 +249,7 @@ class wpGoogleAnalytics {
|
|
145 |
echo '</select>';
|
146 |
echo '</label><br />';
|
147 |
}
|
|
|
148 |
}
|
149 |
|
150 |
public function field_do_not_track() {
|
@@ -300,6 +405,37 @@ class wpGoogleAnalytics {
|
|
300 |
foreach( $this->_get_options( 'custom_vars', array() ) as $i => $custom_var ) {
|
301 |
if ( empty( $custom_var['name'] ) || empty( $custom_var['value'] ) )
|
302 |
continue;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
303 |
$atts = array(
|
304 |
"'_setCustomVar'",
|
305 |
intval( $i ),
|
@@ -394,6 +530,53 @@ class wpGoogleAnalytics {
|
|
394 |
wp_enqueue_script( 'wp-google-analytics', plugin_dir_url( __FILE__ ) . 'wp-google-analytics.js', array( 'jquery' ), '0.0.3' );
|
395 |
}
|
396 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
397 |
}
|
398 |
|
399 |
global $wp_google_analytics;
|
3 |
* Plugin Name: WP Google Analytics
|
4 |
* Plugin URI: http://bluedogwebservices.com/wordpress-plugin/wp-google-analytics/
|
5 |
* Description: Lets you use <a href="http://analytics.google.com">Google Analytics</a> to track your WordPress site statistics
|
6 |
+
* Version: 1.4.0
|
7 |
* Author: Aaron D. Campbell
|
8 |
* Author URI: http://ran.ge/
|
9 |
* License: GPLv2 or later
|
10 |
* Text Domain: wp-google-analytics
|
11 |
*/
|
12 |
|
13 |
+
define('WGA_VERSION', '1.4.0');
|
14 |
|
15 |
/* Copyright 2006 Aaron D. Campbell (email : wp_plugins@xavisys.com)
|
16 |
|
43 |
|
44 |
static $page_slug = 'wp-google-analytics';
|
45 |
|
46 |
+
var $tokens = array();
|
47 |
+
|
48 |
/**
|
49 |
* This is our constructor, which is private to force the use of get_instance()
|
50 |
* @return void
|
51 |
*/
|
52 |
private function __construct() {
|
53 |
+
add_filter( 'init', array( $this, 'init' ) );
|
54 |
add_action( 'admin_init', array( $this, 'admin_init' ) );
|
55 |
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
|
56 |
add_action( 'get_footer', array( $this, 'insert_code' ) );
|
57 |
add_action( 'wp_enqueue_scripts', array( $this, 'track_outgoing' ) );
|
58 |
+
add_filter( 'plugin_action_links', array( $this, 'add_plugin_page_links' ), 10, 2 );
|
59 |
}
|
60 |
|
61 |
/**
|
68 |
return self::$instance;
|
69 |
}
|
70 |
|
71 |
+
public function init() {
|
72 |
load_plugin_textdomain( 'jetpack', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
|
73 |
+
|
74 |
+
$this->tokens = array(
|
75 |
+
array(
|
76 |
+
'token' => '%the_author%',
|
77 |
+
'callback' => 'get_the_author',
|
78 |
+
'callback_returns' => 'string',
|
79 |
+
'description' => __( 'Post author for current view', 'wp-google-analytics' ),
|
80 |
+
'retval' => __( "Post author's display name", 'wp-google-analytics' ),
|
81 |
+
'ignore_when' => array(
|
82 |
+
'is_home',
|
83 |
+
'is_front_page',
|
84 |
+
'is_post_type_archive',
|
85 |
+
'is_page',
|
86 |
+
'is_date',
|
87 |
+
'is_category',
|
88 |
+
'is_tag',
|
89 |
+
),
|
90 |
+
),
|
91 |
+
array(
|
92 |
+
'token' => '%the_category%',
|
93 |
+
'callback' => array( $this, 'token_the_category' ),
|
94 |
+
'callback_returns' => 'string',
|
95 |
+
'description' => __( 'Categories assigned to a post', 'wp-google-analytics' ),
|
96 |
+
'retval' => __( "Category names in a commma-separated list", 'wp-google-analytics' ),
|
97 |
+
'ignore_when' => array(
|
98 |
+
'is_home',
|
99 |
+
'is_front_page',
|
100 |
+
'is_page',
|
101 |
+
'is_post_type_archive',
|
102 |
+
'is_author',
|
103 |
+
'is_tag',
|
104 |
+
),
|
105 |
+
),
|
106 |
+
array(
|
107 |
+
'token' => '%context%',
|
108 |
+
'callback' => array( $this, 'token_context' ),
|
109 |
+
'callback_returns' => 'string',
|
110 |
+
'description' => __( 'Which view the visitor is on', 'wp-google-analytics' ),
|
111 |
+
'retval' => __( "Samples: 'home', 'category', 'post', 'author'" ),
|
112 |
+
),
|
113 |
+
array(
|
114 |
+
'token' => '%the_date%',
|
115 |
+
'callback' => 'get_the_date',
|
116 |
+
'callback_returns' => 'string',
|
117 |
+
'description' => __( 'Publication date for the current view', 'wp-google-analytics' ),
|
118 |
+
'retval' => __( "Format specified by 'Date Format' in Settings -> General", 'wp-google-analytics' ),
|
119 |
+
'ignore_when' => array(
|
120 |
+
'is_home',
|
121 |
+
'is_front_page',
|
122 |
+
'is_post_type_archive',
|
123 |
+
'is_page',
|
124 |
+
'is_author',
|
125 |
+
'is_category',
|
126 |
+
'is_tag',
|
127 |
+
),
|
128 |
+
),
|
129 |
+
array(
|
130 |
+
'token' => '%the_tags%',
|
131 |
+
'callback' => array( $this, 'token_the_tags' ),
|
132 |
+
'callback_returns' => 'string',
|
133 |
+
'description' => __( 'Tags assigned to a post', 'wp-google-analytics' ),
|
134 |
+
'retval' => __( "Tag names in a commma-separated list", 'wp-google-analytics' ),
|
135 |
+
'ignore_when' => array(
|
136 |
+
'is_home',
|
137 |
+
'is_front_page',
|
138 |
+
'is_page',
|
139 |
+
'is_post_type_archive',
|
140 |
+
'is_date',
|
141 |
+
'is_category',
|
142 |
+
'is_author',
|
143 |
+
),
|
144 |
+
),
|
145 |
+
array(
|
146 |
+
'token' => '%is_user_logged_in%',
|
147 |
+
'callback' => 'is_user_logged_in',
|
148 |
+
'callback_returns' => 'bool',
|
149 |
+
'description' => __( 'Whether or not the viewer is logged in', 'wp-google-analytics' ),
|
150 |
+
'retval' => __( "'true' or 'false'", 'wp-google-analytics' ),
|
151 |
+
),
|
152 |
+
);
|
153 |
+
|
154 |
+
$this->tokens = apply_filters( 'wga_tokens', $this->tokens );
|
155 |
}
|
156 |
|
157 |
/**
|
165 |
* Register our settings
|
166 |
*/
|
167 |
public function admin_init() {
|
168 |
+
|
169 |
register_setting( 'wga', 'wga', array( $this, 'sanitize_general_options' ) );
|
170 |
|
171 |
add_settings_section( 'wga_general', false, '__return_false', 'wga' );
|
179 |
* Where the user adds their Google Analytics code
|
180 |
*/
|
181 |
public function field_code() {
|
182 |
+
// Display the tokens in the right column of the page
|
183 |
+
echo '<div id="tokens-description" style="position:absolute;margin-left:600px;margin-right:50px;">';
|
184 |
+
echo '<span>' . __( 'Use tokens in your custom variables to make your fields dynamic based on context. Here are some of the tokens you can use:' ) . '</span>';
|
185 |
+
echo '<table style="text-align:left;">';
|
186 |
+
echo '<thead><tr><td>' . __( 'Token', 'wp-google-analytics' ) . '</td><td>' . __( 'Description', 'wp-google-analytics' ) . '</td><td>' . __( 'Return value', 'wp-google-analytics' ) . '</td></tr></thead>';
|
187 |
+
echo '<tbody>';
|
188 |
+
foreach( $this->tokens as $token ) {
|
189 |
+
echo '<tr>';
|
190 |
+
echo '<td>' . esc_html( $token['token'] ) . '</td>';
|
191 |
+
echo '<td>' . esc_html( $token['description'] ) . '</td>';
|
192 |
+
echo '<td>' . esc_html( $token['retval'] ) . '</td>';
|
193 |
+
echo '</tr>';
|
194 |
+
}
|
195 |
+
echo '</tbody>';
|
196 |
+
echo '</table>';
|
197 |
+
echo '</div>';
|
198 |
+
|
199 |
echo '<input name="wga[code]" id="wga-code" type="text" value="' . esc_attr( $this->_get_options( 'code' ) ) . '" />';
|
200 |
echo '<p class="description">' . __( 'Paste your Google Analytics tracking ID (e.g. "UA-XXXXXX-X") into the field.', 'wp-google-analytics' ) . '</p>';
|
201 |
}
|
221 |
* Define custom variables to be included in your tracking code
|
222 |
*/
|
223 |
public function field_custom_variables() {
|
224 |
+
|
225 |
$custom_vars = $this->_get_options( 'custom_vars' );
|
226 |
|
227 |
$scope_options = array(
|
249 |
echo '</select>';
|
250 |
echo '</label><br />';
|
251 |
}
|
252 |
+
|
253 |
}
|
254 |
|
255 |
public function field_do_not_track() {
|
405 |
foreach( $this->_get_options( 'custom_vars', array() ) as $i => $custom_var ) {
|
406 |
if ( empty( $custom_var['name'] ) || empty( $custom_var['value'] ) )
|
407 |
continue;
|
408 |
+
|
409 |
+
// Check whether a token was used with this custom var, and replace with value if so
|
410 |
+
$all_tokens = wp_list_pluck( $this->tokens, 'token' );
|
411 |
+
if ( in_array( $custom_var['value'], $all_tokens ) ) {
|
412 |
+
$token = array_pop( wp_filter_object_list( $this->tokens, array( 'token' => $custom_var['value'] ) ) );
|
413 |
+
|
414 |
+
// Allow tokens to return empty values for specific contexts
|
415 |
+
$ignore = false;
|
416 |
+
if ( ! empty( $token['ignore_when'] ) ) {
|
417 |
+
foreach( (array)$token['ignore_when'] as $conditional ) {
|
418 |
+
if ( is_callable( $conditional ) ) {
|
419 |
+
$ignore = call_user_func( $conditional );
|
420 |
+
if ( $ignore )
|
421 |
+
break;
|
422 |
+
}
|
423 |
+
}
|
424 |
+
}
|
425 |
+
|
426 |
+
// If we aren't set to ignore this context, possibly execute the callback
|
427 |
+
if ( ! $ignore && ! empty( $token['callback'] ) && is_callable( $token['callback'] ) )
|
428 |
+
$replace = call_user_func( $token['callback'] );
|
429 |
+
else
|
430 |
+
$replace = '';
|
431 |
+
|
432 |
+
if ( ! empty( $token['callback_returns'] ) && 'bool' == $token['callback_returns'] )
|
433 |
+
$replace = ( $replace ) ? 'true' : 'false';
|
434 |
+
|
435 |
+
// Replace our token with the value
|
436 |
+
$custom_var['value'] = str_replace( $custom_var['value'], $replace, $custom_var['value'] );
|
437 |
+
}
|
438 |
+
|
439 |
$atts = array(
|
440 |
"'_setCustomVar'",
|
441 |
intval( $i ),
|
530 |
wp_enqueue_script( 'wp-google-analytics', plugin_dir_url( __FILE__ ) . 'wp-google-analytics.js', array( 'jquery' ), '0.0.3' );
|
531 |
}
|
532 |
|
533 |
+
/**
|
534 |
+
* Callback for %the_category% token
|
535 |
+
*/
|
536 |
+
public function token_the_category() {
|
537 |
+
return implode( ', ', wp_list_pluck( (array)get_the_category(), 'name' ) );
|
538 |
+
}
|
539 |
+
|
540 |
+
/**
|
541 |
+
* Callback for %context% token
|
542 |
+
*/
|
543 |
+
public function token_context() {
|
544 |
+
if ( is_admin() ) {
|
545 |
+
return 'admin';
|
546 |
+
} else if ( is_home() || is_front_page() ) {
|
547 |
+
return 'home';
|
548 |
+
} else if ( is_tax() || is_tag() || is_category() ) {
|
549 |
+
return get_queried_object()->taxonomy;
|
550 |
+
} else if ( is_author() ) {
|
551 |
+
return 'author';
|
552 |
+
} else if ( is_singular() || is_single() || is_page() ) {
|
553 |
+
return get_post_type();
|
554 |
+
} else if ( is_search() ) {
|
555 |
+
return 'search';
|
556 |
+
} else if ( is_date() ) {
|
557 |
+
return 'date';
|
558 |
+
} else if ( is_archive() ) {
|
559 |
+
return 'archive';
|
560 |
+
} else if ( is_404() ) {
|
561 |
+
return '404';
|
562 |
+
}
|
563 |
+
}
|
564 |
+
|
565 |
+
/**
|
566 |
+
* Callback for %the_tags% token
|
567 |
+
*/
|
568 |
+
public function token_the_tags() {
|
569 |
+
return implode( ', ', wp_list_pluck( (array)get_the_tags(), 'name' ) );
|
570 |
+
}
|
571 |
+
|
572 |
+
public function add_plugin_page_links( $links, $file ){
|
573 |
+
if ( plugin_basename( __FILE__ ) == $file ) {
|
574 |
+
$link = '<a href="' . admin_url( 'options-general.php?page=' . self::$page_slug ) . '">' . __( 'Settings', 'wp-google-analytics' ) . '</a>';
|
575 |
+
array_unshift( $links, $link );
|
576 |
+
}
|
577 |
+
return $links;
|
578 |
+
}
|
579 |
+
|
580 |
}
|
581 |
|
582 |
global $wp_google_analytics;
|