Google Analytics - Version 1.0

Version Description

  • Initial release
Download this release

Release Info

Developer webkinder
Plugin Icon 128x128 Google Analytics
Version 1.0
Comparing to
See all releases

Version 1.0

css/admin-styles.css ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Google Analytics by WebKinder
3
+ * Admin CSS Styles
4
+ */
5
+
6
+ #track-device button.wk-button.not-tracked {
7
+ background-color: #c9ffc9;
8
+ }
9
+
10
+ #wk-google-analytics-settings>div {
11
+ margin-bottom: 15px;
12
+ }
js/admin-functions.js ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Google Analytics by WebKinder
3
+ * Admin JS Functions
4
+ */
5
+
6
+ var WKGA_AdminFunctions = {
7
+ CookieName: 'wp_wk_ga_untrack_' + document.location.hostname,
8
+ UntrackText: text_content.UntrackText,
9
+ TrackText: text_content.TrackText,
10
+
11
+ init: function( containerID ) {
12
+ this.containerID = containerID;
13
+ this.buttonSelector = containerID + " .wk-button";
14
+ jQuery( containerID ).html('<button class="wk-button button-secondary"></button>');
15
+
16
+ this.renderButton();
17
+
18
+ jQuery( containerID + " .wk-button" ).click( function() {
19
+ this.handleClick();
20
+ }.bind(this) );
21
+
22
+ },
23
+
24
+ renderButton: function( containerID ) {
25
+ var buttonText = Cookies.get( this.CookieName ) ? this.UntrackText : this.TrackText;
26
+ var buttonClass = Cookies.get( this.CookieName ) ? "not-tracked" : "tracked";
27
+ jQuery( this.buttonSelector ).removeClass('tracked not-tracked').addClass(buttonClass).text( buttonText );
28
+ },
29
+
30
+ handleClick: function() {
31
+ if( Cookies.get( this.CookieName ) ) {
32
+ Cookies.remove( this.CookieName );
33
+ } else {
34
+ Cookies.set( this.CookieName , true, { expires: 365 } );
35
+ }
36
+ this.renderButton();
37
+ console.log( document.cookie );
38
+ }
39
+
40
+ }
41
+
42
+ jQuery(document).ready(function(){
43
+
44
+ WKGA_AdminFunctions.init( '#track-device' );
45
+
46
+ });
js/js.cookie.js ADDED
@@ -0,0 +1,151 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*!
2
+ * JavaScript Cookie v2.1.2
3
+ * https://github.com/js-cookie/js-cookie
4
+ *
5
+ * Copyright 2006, 2015 Klaus Hartl & Fagner Brack
6
+ * Released under the MIT license
7
+ */
8
+ ;(function (factory) {
9
+ if (typeof define === 'function' && define.amd) {
10
+ define(factory);
11
+ } else if (typeof exports === 'object') {
12
+ module.exports = factory();
13
+ } else {
14
+ var OldCookies = window.Cookies;
15
+ var api = window.Cookies = factory();
16
+ api.noConflict = function () {
17
+ window.Cookies = OldCookies;
18
+ return api;
19
+ };
20
+ }
21
+ }(function () {
22
+ function extend () {
23
+ var i = 0;
24
+ var result = {};
25
+ for (; i < arguments.length; i++) {
26
+ var attributes = arguments[ i ];
27
+ for (var key in attributes) {
28
+ result[key] = attributes[key];
29
+ }
30
+ }
31
+ return result;
32
+ }
33
+
34
+ function init (converter) {
35
+ function api (key, value, attributes) {
36
+ var result;
37
+ if (typeof document === 'undefined') {
38
+ return;
39
+ }
40
+
41
+ // Write
42
+
43
+ if (arguments.length > 1) {
44
+ attributes = extend({
45
+ path: '/'
46
+ }, api.defaults, attributes);
47
+
48
+ if (typeof attributes.expires === 'number') {
49
+ var expires = new Date();
50
+ expires.setMilliseconds(expires.getMilliseconds() + attributes.expires * 864e+5);
51
+ attributes.expires = expires;
52
+ }
53
+
54
+ try {
55
+ result = JSON.stringify(value);
56
+ if (/^[\{\[]/.test(result)) {
57
+ value = result;
58
+ }
59
+ } catch (e) {}
60
+
61
+ if (!converter.write) {
62
+ value = encodeURIComponent(String(value))
63
+ .replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent);
64
+ } else {
65
+ value = converter.write(value, key);
66
+ }
67
+
68
+ key = encodeURIComponent(String(key));
69
+ key = key.replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent);
70
+ key = key.replace(/[\(\)]/g, escape);
71
+
72
+ return (document.cookie = [
73
+ key, '=', value,
74
+ attributes.expires && '; expires=' + attributes.expires.toUTCString(), // use expires attribute, max-age is not supported by IE
75
+ attributes.path && '; path=' + attributes.path,
76
+ attributes.domain && '; domain=' + attributes.domain,
77
+ attributes.secure ? '; secure' : ''
78
+ ].join(''));
79
+ }
80
+
81
+ // Read
82
+
83
+ if (!key) {
84
+ result = {};
85
+ }
86
+
87
+ // To prevent the for loop in the first place assign an empty array
88
+ // in case there are no cookies at all. Also prevents odd result when
89
+ // calling "get()"
90
+ var cookies = document.cookie ? document.cookie.split('; ') : [];
91
+ var rdecode = /(%[0-9A-Z]{2})+/g;
92
+ var i = 0;
93
+
94
+ for (; i < cookies.length; i++) {
95
+ var parts = cookies[i].split('=');
96
+ var cookie = parts.slice(1).join('=');
97
+
98
+ if (cookie.charAt(0) === '"') {
99
+ cookie = cookie.slice(1, -1);
100
+ }
101
+
102
+ try {
103
+ var name = parts[0].replace(rdecode, decodeURIComponent);
104
+ cookie = converter.read ?
105
+ converter.read(cookie, name) : converter(cookie, name) ||
106
+ cookie.replace(rdecode, decodeURIComponent);
107
+
108
+ if (this.json) {
109
+ try {
110
+ cookie = JSON.parse(cookie);
111
+ } catch (e) {}
112
+ }
113
+
114
+ if (key === name) {
115
+ result = cookie;
116
+ break;
117
+ }
118
+
119
+ if (!key) {
120
+ result[name] = cookie;
121
+ }
122
+ } catch (e) {}
123
+ }
124
+
125
+ return result;
126
+ }
127
+
128
+ api.set = api;
129
+ api.get = function (key) {
130
+ return api(key);
131
+ };
132
+ api.getJSON = function () {
133
+ return api.apply({
134
+ json: true
135
+ }, [].slice.call(arguments));
136
+ };
137
+ api.defaults = {};
138
+
139
+ api.remove = function (key, attributes) {
140
+ api(key, '', extend(attributes, {
141
+ expires: -1
142
+ }));
143
+ };
144
+
145
+ api.withConverter = init;
146
+
147
+ return api;
148
+ }
149
+
150
+ return init(function () {});
151
+ }));
lang/wk-ga-de_CH.mo ADDED
Binary file
lang/wk-ga-de_CH.po ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: Google Analytics by WebKinder\n"
4
+ "POT-Creation-Date: 2016-07-21 09:33+0200\n"
5
+ "PO-Revision-Date: 2016-07-21 09:35+0200\n"
6
+ "Last-Translator: \n"
7
+ "Language-Team: \n"
8
+ "Language: de\n"
9
+ "MIME-Version: 1.0\n"
10
+ "Content-Type: text/plain; charset=UTF-8\n"
11
+ "Content-Transfer-Encoding: 8bit\n"
12
+ "X-Generator: Poedit 1.8.8\n"
13
+ "X-Poedit-Basepath: ..\n"
14
+ "Plural-Forms: nplurals=2; plural=(n != 1);\n"
15
+ "X-Poedit-SourceCharset: UTF-8\n"
16
+ "X-Poedit-KeywordsList: __;_e\n"
17
+ "X-Poedit-SearchPath-0: wk-ga.php\n"
18
+
19
+ #: wk-ga.php:95
20
+ msgid "Page visits from this device are not tracked."
21
+ msgstr "Seitenbesuche von diesem Gerät werden nicht getrackt."
22
+
23
+ #: wk-ga.php:96
24
+ msgid "This device is treated like any other"
25
+ msgstr "Dieses Gerät wird wie jedes Andere behandelt."
26
+
27
+ #: wk-ga.php:154
28
+ msgid "Test your tracking code now!"
29
+ msgstr "Teste deinen Tracking Code jetzt!"
30
+
31
+ #: wk-ga.php:158
32
+ msgid ""
33
+ "Enter your Google Analytics tracking code below. There are two additional "
34
+ "mechanisms that allow you to stop tracking your own visits. The first one "
35
+ "checks if you are logged in as a WordPress User. The second one allows you "
36
+ "to stop tracking certain devices totally by setting a cookie."
37
+ msgstr ""
38
+ "Gib deinen Google Analytics Tracking Code unten ein. Es gibt zwei "
39
+ "zusätzliche Mechanismen, die dir erlauben deine eigenen Seitenbesuche "
40
+ "nicht mehr zu tracken. Der erste prüft, ob du als WordPress User "
41
+ "angemeldet bist. Der zweite gibt dir die Möglichkeit über ein Cookie "
42
+ "sämtliche Seitenbesuche von einem bestimmten Gerät aus nicht mehr zu "
43
+ "tracken."
44
+
45
+ #: wk-ga.php:166
46
+ msgid "GA Tracking Code"
47
+ msgstr "GA Tracking Code"
48
+
49
+ #: wk-ga.php:170
50
+ msgid "Track logged in users"
51
+ msgstr "Eingeloggte Benutzer tracken"
lang/wk-ga-de_DE.mo ADDED
Binary file
lang/wk-ga-de_DE.po ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: Google Analytics by WebKinder\n"
4
+ "POT-Creation-Date: 2016-07-21 09:33+0200\n"
5
+ "PO-Revision-Date: 2016-07-21 09:35+0200\n"
6
+ "Last-Translator: \n"
7
+ "Language-Team: \n"
8
+ "Language: de\n"
9
+ "MIME-Version: 1.0\n"
10
+ "Content-Type: text/plain; charset=UTF-8\n"
11
+ "Content-Transfer-Encoding: 8bit\n"
12
+ "X-Generator: Poedit 1.8.8\n"
13
+ "X-Poedit-Basepath: ..\n"
14
+ "Plural-Forms: nplurals=2; plural=(n != 1);\n"
15
+ "X-Poedit-SourceCharset: UTF-8\n"
16
+ "X-Poedit-KeywordsList: __;_e\n"
17
+ "X-Poedit-SearchPath-0: wk-ga.php\n"
18
+
19
+ #: wk-ga.php:95
20
+ msgid "Page visits from this device are not tracked."
21
+ msgstr "Seitenbesuche von diesem Gerät werden nicht getrackt."
22
+
23
+ #: wk-ga.php:96
24
+ msgid "This device is treated like any other"
25
+ msgstr "Dieses Gerät wird wie jedes Andere behandelt."
26
+
27
+ #: wk-ga.php:154
28
+ msgid "Test your tracking code now!"
29
+ msgstr "Teste deinen Tracking Code jetzt!"
30
+
31
+ #: wk-ga.php:158
32
+ msgid ""
33
+ "Enter your Google Analytics tracking code below. There are two additional "
34
+ "mechanisms that allow you to stop tracking your own visits. The first one "
35
+ "checks if you are logged in as a WordPress User. The second one allows you "
36
+ "to stop tracking certain devices totally by setting a cookie."
37
+ msgstr ""
38
+ "Gib deinen Google Analytics Tracking Code unten ein. Es gibt zwei "
39
+ "zusätzliche Mechanismen, die dir erlauben deine eigenen Seitenbesuche "
40
+ "nicht mehr zu tracken. Der erste prüft, ob du als WordPress User "
41
+ "angemeldet bist. Der zweite gibt dir die Möglichkeit über ein Cookie "
42
+ "sämtliche Seitenbesuche von einem bestimmten Gerät aus nicht mehr zu "
43
+ "tracken."
44
+
45
+ #: wk-ga.php:166
46
+ msgid "GA Tracking Code"
47
+ msgstr "GA Tracking Code"
48
+
49
+ #: wk-ga.php:170
50
+ msgid "Track logged in users"
51
+ msgstr "Eingeloggte Benutzer tracken"
readme.txt ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Google Analytics ===
2
+ Contributors: webkinder
3
+ Tags: google analytics, tracking code
4
+ Requires at least: 3.0
5
+ Tested up to: 4.6
6
+ Stable tag: 1.0
7
+ License: GPLv2 or later
8
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
+
10
+ Google Analytics for WordPress without tracking your own visits.
11
+
12
+ == Description ==
13
+
14
+ Enable Google Analytics on all pages without tracking your own visits. You can exclude any logged in user as well as ignore a device completely by setting a cookie.
15
+
16
+ If you have any questions or feature requests, feel free to contact us via support@webkinder.ch.
17
+
18
+ == Installation ==
19
+
20
+ 1. Upload the plugin files to the `/wp-content/plugins/wk-ga directory, or install the plugin through the WordPress plugins screen directly.
21
+ 1. Activate the plugin through the 'Plugins' screen in WordPress
22
+ 1. Use the Settings->Google Analytics screen to configure the plugin
23
+ 1. Test your Tracking Code as shown [here](https://support.google.com/analytics/answer/1008083?hl=en)
24
+
25
+ == Screenshots ==
26
+
27
+ 1.The Settings Page of this Plugin. The cookie mechanism is activated here.
28
+
29
+ == Changelog ==
30
+
31
+ = 1.0 =
32
+ * Initial release
wk-ga.php ADDED
@@ -0,0 +1,190 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: Google Analytics by WebKinder
4
+ Plugin URI: https://wordpress.org/plugins/wk-google-analytics/
5
+ Description: Google Analytics for WordPress without tracking your own visits
6
+ Version: 1.0
7
+ Author: WebKinder
8
+ Author URI: http://www.webkinder.ch
9
+ License: GPL2
10
+ License URI: https://www.gnu.org/licenses/gpl-2.0.html
11
+ Domain Path: /lang
12
+ Text Domain: wk-ga
13
+ */
14
+
15
+ class wk_ga {
16
+ public function __construct() {
17
+
18
+ //Lifecycle hooks
19
+ register_activation_hook( __FILE__, array( $this, "activation" ) );
20
+ register_deactivation_hook( __FILE__, array( $this, "deactivation" ) );
21
+
22
+ //i18n
23
+ add_action('plugins_loaded', array( $this, "load_textdomain") );
24
+
25
+ //Settings
26
+ add_action( 'admin_init', array( $this, "register_settings" ) );
27
+ add_action( 'admin_menu', array( $this, "settings_page" ) );
28
+
29
+ //Cookie Handling
30
+ add_action( 'admin_enqueue_scripts', array( $this, "load_admin_scripts" ) );
31
+
32
+ //Load GA Code on Frontend
33
+ add_action( 'wp_footer', array( $this, "render_ga_script" ) );
34
+ }
35
+
36
+ /*
37
+ * Load Text Domain
38
+ */
39
+ function load_textdomain() {
40
+ load_plugin_textdomain( 'wk-ga', false, dirname( plugin_basename(__FILE__) ) . '/lang/' );
41
+ }
42
+
43
+ /*
44
+ * Plugin Activation
45
+ */
46
+ public function activation() {
47
+
48
+ //set setting defaults
49
+ update_option( 'track_logged_in', false );
50
+ }
51
+
52
+ /*
53
+ * Plugin Deactivation
54
+ */
55
+ public function deactivation() {
56
+
57
+ //remove cookie
58
+
59
+ }
60
+
61
+ /*
62
+ * Register Settings
63
+ */
64
+ public function register_settings() {
65
+ register_setting(
66
+ 'wk_ga_google_analytics', // settings section
67
+ 'ga_tracking_code' // setting name
68
+ );
69
+
70
+ register_setting(
71
+ 'wk_ga_google_analytics', // settings section
72
+ 'track_logged_in' // setting name
73
+ );
74
+ }
75
+
76
+ /*
77
+ *
78
+ */
79
+ public function load_admin_scripts( $hook ) {
80
+ if( $hook != "settings_page_google_analytics" ) {
81
+ return;
82
+ }
83
+
84
+ //admin styles
85
+ wp_enqueue_style( 'custom-admin-styles', plugin_dir_url( __FILE__ ) . '/css/admin-styles.css' );
86
+
87
+ //cookie library
88
+ wp_enqueue_script( 'cookie-js', plugin_dir_url( __FILE__ ) . '/js/js.cookie.js' );
89
+
90
+ //admin js for cookies
91
+ wp_register_script( 'wk-ga-admin-js', plugin_dir_url( __FILE__ ) . '/js/admin-functions.js', array('jquery', 'cookie-js') );
92
+
93
+ //translate JavaScript
94
+ $translation_array = array(
95
+ 'UntrackText' => __('Page visits from this device are not tracked.','wk-ga'),
96
+ 'TrackText' => __('This device is treated like any other','wk-ga')
97
+ );
98
+ wp_localize_script('wk-ga-admin-js', 'text_content', $translation_array );
99
+ wp_enqueue_script('wk-ga-admin-js');
100
+
101
+ }
102
+
103
+ public function render_ga_script() {
104
+ $GA_CODE = get_option('ga_tracking_code');
105
+ $TRACK_LOGGED_IN = get_option('track_logged_in');
106
+
107
+ if( $GA_CODE && ( (!$TRACK_LOGGED_IN && !is_user_logged_in()) || $TRACK_LOGGED_IN ) ) :
108
+ ?>
109
+
110
+ <script>
111
+
112
+ if( !
113
+ (new RegExp('wp_wk_ga_untrack_' + document.location.hostname) ).test(document.cookie)
114
+ )
115
+ {
116
+ console.log('THIS VISIT GETS TRACKED');
117
+
118
+ //GA Tracking Snippet
119
+ (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
120
+ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
121
+ m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
122
+ })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
123
+ ga('create', '<?php echo $GA_CODE; ?>', 'auto');
124
+ ga('send', 'pageview');
125
+ }
126
+ </script>
127
+
128
+ <?php
129
+
130
+ endif;
131
+ }
132
+
133
+ /*
134
+ * Settings Page
135
+ */
136
+ public function settings_page() {
137
+ add_options_page(
138
+ 'Google Analytics',
139
+ 'Google Analytics',
140
+ 'manage_options',
141
+ 'google_analytics',
142
+ array( $this, "settings_content" )
143
+ );
144
+ }
145
+
146
+ public function settings_content() {
147
+ if ( ! isset( $_REQUEST['settings-updated'] ) )
148
+ $_REQUEST['settings-updated'] = false;
149
+ ?>
150
+ <div class="wrap">
151
+ <h2><?php echo esc_html( get_admin_page_title() ); ?></h2>
152
+
153
+ <?php if ( false !== $_REQUEST['settings-updated'] ) : ?>
154
+ <div class="updated fade"><p><strong><a target="_blank" href="https://support.google.com/analytics/answer/1008083?hl=de"><?php _e( 'Test your tracking code now!', 'wk-ga' ); ?></a></strong></p>
155
+ </div>
156
+ <?php endif; ?>
157
+
158
+ <p><?php _e('Enter your Google Analytics tracking code below. There are two additional mechanisms that allow you to stop tracking your own visits. The first one checks if you are logged in as a WordPress User. The second one allows you to stop tracking certain devices totally by setting a cookie.', 'wk-ga'); ?>
159
+ </p>
160
+
161
+ <form id="wk-google-analytics-settings" method="post" action="options.php">
162
+ <?php settings_fields( 'wk_ga_google_analytics' ); ?>
163
+ <?php do_settings_sections('wk_ga_google_analytics'); ?>
164
+
165
+ <div>
166
+ <label><?php _e('GA Tracking Code', 'wk-ga'); ?></label>
167
+ <input type="text" name="ga_tracking_code" value=<?php echo esc_attr( get_option( "ga_tracking_code" ) ); ?> />
168
+ </div>
169
+ <div>
170
+ <label><?php _e('Track logged in users', 'wk-ga'); ?></label>
171
+ <input type="checkbox" name="track_logged_in" value="1" <?php checked( get_option( "track_logged_in" ) )?> />
172
+ </div>
173
+ <?php submit_button(); ?>
174
+ </form>
175
+
176
+ <div>
177
+ <p></p>
178
+ <div id="track-device"></div>
179
+ </div>
180
+
181
+ </div>
182
+
183
+ <?php
184
+ }
185
+
186
+ }
187
+
188
+ $wk_ga = new wk_ga();
189
+
190
+ ?>