Google Analytics - Version 1.2

Version Description

  • added support for Google Tag Manager
Download this release

Release Info

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

Version 1.2

css/admin-styles.css ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ }
13
+
14
+ #mc_embed_signup .mc-field-group {
15
+ margin-bottom: 15px;
16
+ }
js/admin-functions.js ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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, useTagManager ) {
12
+
13
+ //cookie handling
14
+ this.containerID = containerID;
15
+ this.buttonSelector = containerID + " .wk-button";
16
+ jQuery( containerID ).html('<button class="wk-button button-secondary"></button>');
17
+
18
+ this.renderButton();
19
+
20
+ jQuery( containerID + " .wk-button" ).click( function() {
21
+ this.handleClick();
22
+ }.bind(this) );
23
+
24
+ //analytics/tag manager switch
25
+ this.onlyUseOne( jQuery( useTagManager ).is(":checked") );
26
+
27
+ jQuery( useTagManager ).change( function() {
28
+ this.onlyUseOne( jQuery( useTagManager ).is(":checked") );
29
+ }.bind(this));
30
+
31
+ },
32
+
33
+ onlyUseOne: function( useIt ) {
34
+ switch( useIt ) {
35
+ case true: {
36
+ console.log('checked');
37
+ jQuery('.use-google-tag-manager').children('input').prop('readonly', false);
38
+ jQuery('.use-google-analytics').children('input').prop('readonly', true);
39
+ break;
40
+ }
41
+ case false: {
42
+ jQuery('.use-google-analytics').children('input').prop('readonly', false);
43
+ jQuery('.use-google-tag-manager').children('input').prop('readonly', true);
44
+ console.log('not checked');
45
+ break;
46
+ }
47
+ }
48
+ },
49
+
50
+ renderButton: function( containerID ) {
51
+ var buttonText = Cookies.get( this.CookieName ) ? this.UntrackText : this.TrackText;
52
+ var buttonClass = Cookies.get( this.CookieName ) ? "not-tracked" : "tracked";
53
+ jQuery( this.buttonSelector ).removeClass('tracked not-tracked').addClass(buttonClass).text( buttonText );
54
+ },
55
+
56
+ handleClick: function() {
57
+ if( Cookies.get( this.CookieName ) ) {
58
+ Cookies.remove( this.CookieName );
59
+ } else {
60
+ Cookies.set( this.CookieName , true, { expires: 365 } );
61
+ }
62
+ this.renderButton();
63
+ console.log( document.cookie );
64
+ }
65
+
66
+ }
67
+
68
+ jQuery(document).ready(function(){
69
+
70
+ WKGA_AdminFunctions.init( '#track-device', '#use-google-tag-manager' );
71
+
72
+ });
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,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: Google Analytics by WebKinder\n"
4
+ "POT-Creation-Date: 2016-10-03 10:37+0200\n"
5
+ "PO-Revision-Date: 2016-10-03 10:38+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.9\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:190
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:191
24
+ msgid "This device is treated like any other"
25
+ msgstr "Dieses Gerät wird wie jedes Andere behandelt."
26
+
27
+ #: wk-ga.php:219
28
+ msgid "Test your tracking code now!"
29
+ msgstr "Teste deinen Tracking Code jetzt!"
30
+
31
+ #: wk-ga.php:223
32
+ msgid ""
33
+ "Enter your Google Analytics tracking code below. You can also use Google Tag "
34
+ "Manager instead by checking the relevant setting."
35
+ msgstr ""
36
+ "Gib deinen Google Analytics Tracking Code unten ein. Alternativ kann auch "
37
+ "Google Tag Manager verwendet werden, indem das entsprechende Setting gesetzt "
38
+ "wird."
39
+
40
+ #: wk-ga.php:231
41
+ msgid "GA Tracking Code"
42
+ msgstr "GA Tracking Code"
43
+
44
+ #: wk-ga.php:235
45
+ msgid "Anonymize IP's"
46
+ msgstr "IP Anonymisierung"
47
+
48
+ #: wk-ga.php:239
49
+ msgid "Track logged in users"
50
+ msgstr "Eingeloggte Benutzer tracken"
51
+
52
+ #: wk-ga.php:243
53
+ msgid "Use Google tag manager instead"
54
+ msgstr "Benutze Google Tag Manager"
55
+
56
+ #: wk-ga.php:247
57
+ msgid "Google Tag Manager ID"
58
+ msgstr "Google Tag Manager ID"
59
+
60
+ #: wk-ga.php:261
61
+ msgid "Email Address"
62
+ msgstr "Email Adresse"
63
+
64
+ #: wk-ga.php:266
65
+ msgid "First Name"
66
+ msgstr "Vorname"
67
+
68
+ #: wk-ga.php:270
69
+ msgid "Last Name"
70
+ msgstr "Nachname"
71
+
72
+ #~ msgid ""
73
+ #~ "Enter your Google Analytics tracking code below. There are two additional "
74
+ #~ "mechanisms that allow you to stop tracking your own visits. The first one "
75
+ #~ "checks if you are logged in as a WordPress User. The second one allows "
76
+ #~ "you to stop tracking certain devices totally by setting a cookie."
77
+ #~ msgstr ""
78
+ #~ "Gib deinen Google Analytics Tracking Code unten ein. Es gibt zwei "
79
+ #~ "zusätzliche Mechanismen, die dir erlauben deine eigenen Seitenbesuche "
80
+ #~ "nicht mehr zu tracken. Der erste prüft, ob du als WordPress User "
81
+ #~ "angemeldet bist. Der zweite gibt dir die Möglichkeit über ein Cookie "
82
+ #~ "sämtliche Seitenbesuche von einem bestimmten Gerät aus nicht mehr zu "
83
+ #~ "tracken."
lang/wk-ga-de_DE.mo ADDED
Binary file
lang/wk-ga-de_DE.po ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: Google Analytics by WebKinder\n"
4
+ "POT-Creation-Date: 2016-10-03 10:37+0200\n"
5
+ "PO-Revision-Date: 2016-10-03 10:38+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.9\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:190
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:191
24
+ msgid "This device is treated like any other"
25
+ msgstr "Dieses Gerät wird wie jedes Andere behandelt."
26
+
27
+ #: wk-ga.php:219
28
+ msgid "Test your tracking code now!"
29
+ msgstr "Teste deinen Tracking Code jetzt!"
30
+
31
+ #: wk-ga.php:223
32
+ msgid ""
33
+ "Enter your Google Analytics tracking code below. You can also use Google Tag "
34
+ "Manager instead by checking the relevant setting."
35
+ msgstr ""
36
+ "Gib deinen Google Analytics Tracking Code unten ein. Alternativ kann auch "
37
+ "Google Tag Manager verwendet werden, indem das entsprechende Setting gesetzt "
38
+ "wird."
39
+
40
+ #: wk-ga.php:231
41
+ msgid "GA Tracking Code"
42
+ msgstr "GA Tracking Code"
43
+
44
+ #: wk-ga.php:235
45
+ msgid "Anonymize IP's"
46
+ msgstr "IP Anonymisierung"
47
+
48
+ #: wk-ga.php:239
49
+ msgid "Track logged in users"
50
+ msgstr "Eingeloggte Benutzer tracken"
51
+
52
+ #: wk-ga.php:243
53
+ msgid "Use Google tag manager instead"
54
+ msgstr "Benutze Google Tag Manager"
55
+
56
+ #: wk-ga.php:247
57
+ msgid "Google Tag Manager ID"
58
+ msgstr "Google Tag Manager ID"
59
+
60
+ #: wk-ga.php:261
61
+ msgid "Email Address"
62
+ msgstr "Email Adresse"
63
+
64
+ #: wk-ga.php:266
65
+ msgid "First Name"
66
+ msgstr "Vorname"
67
+
68
+ #: wk-ga.php:270
69
+ msgid "Last Name"
70
+ msgstr "Nachname"
71
+
72
+ #~ msgid ""
73
+ #~ "Enter your Google Analytics tracking code below. There are two additional "
74
+ #~ "mechanisms that allow you to stop tracking your own visits. The first one "
75
+ #~ "checks if you are logged in as a WordPress User. The second one allows "
76
+ #~ "you to stop tracking certain devices totally by setting a cookie."
77
+ #~ msgstr ""
78
+ #~ "Gib deinen Google Analytics Tracking Code unten ein. Es gibt zwei "
79
+ #~ "zusätzliche Mechanismen, die dir erlauben deine eigenen Seitenbesuche "
80
+ #~ "nicht mehr zu tracken. Der erste prüft, ob du als WordPress User "
81
+ #~ "angemeldet bist. Der zweite gibt dir die Möglichkeit über ein Cookie "
82
+ #~ "sämtliche Seitenbesuche von einem bestimmten Gerät aus nicht mehr zu "
83
+ #~ "tracken."
readme.txt ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.2
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
33
+
34
+ = 1.1 =
35
+ * added anonymize IP's option
36
+ * added uninstall file
37
+
38
+ = 1.2 =
39
+ * added support for Google Tag Manager
uninstall.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ // If uninstall is not called from WordPress, exit
3
+ if ( !defined( 'WP_UNINSTALL_PLUGIN' ) ) {
4
+ exit();
5
+ }
6
+
7
+ delete_option( 'ga_tracking_code' );
8
+ delete_option( 'track_logged_in' );
9
+ delete_option( 'ga_anonymize_ip' );
10
+ delete_option( 'ga_use_tag_manager' );
11
+ delete_option('ga_tag_manager_id');
12
+
13
+ // For site options in Multisite
14
+ delete_site_option( 'ga_tracking_code' );
15
+ delete_site_option( 'track_logged_in' );
16
+ delete_site_option( 'ga_anonymize_ip' );
17
+ delete_site_option( 'ga_use_tag_manager' );
18
+ delete_site_option('ga_tag_manager_id');
19
+ ?>
wk-ga.php ADDED
@@ -0,0 +1,292 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.2
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
+ //Cookie function
33
+ add_action( 'wp_head', array( $this, 'render_script') );
34
+
35
+ //Google Analytics code in <head>
36
+ add_action( 'wp_head', array( $this, 'google_analytics_script') );
37
+
38
+ //Google Tag Manager in footer
39
+ add_action( 'wp_footer', array( $this, 'google_tag_manager_script'));
40
+ }
41
+
42
+ /*
43
+ * Should Track Visit
44
+ */
45
+ function should_track_visit() {
46
+ return ( !is_user_logged_in() || get_option('track_logged_in') );
47
+ }
48
+
49
+ /*
50
+ * Render Script
51
+ */
52
+ function render_script() {
53
+ ?>
54
+ <script>
55
+ function hasWKGoogleAnalyticsCookie() {
56
+ return (new RegExp('wp_wk_ga_untrack_' + document.location.hostname) ).test(document.cookie);
57
+ }
58
+ </script>
59
+ <?php
60
+ }
61
+
62
+ /*
63
+ * Tag Manager Script Tag
64
+ */
65
+ function google_tag_manager_script() {
66
+ if( $this->should_track_visit() && get_option('ga_use_tag_manager') ) {
67
+ $TAG_MANAGER_ID = get_option('ga_tag_manager_id');
68
+ ?>
69
+ <noscript><iframe src="//www.googletagmanager.com/ns.html?id=<?php echo $TAG_MANAGER_ID; ?>"
70
+ height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
71
+ <script>
72
+ if( !hasWKGoogleAnalyticsCookie() ) {
73
+ //Google Tag Manager
74
+ (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
75
+ new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
76
+ j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
77
+ '//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
78
+ })(window,document,'script','dataLayer','<?php echo $TAG_MANAGER_ID; ?>');
79
+ }
80
+ </script>
81
+ <?php
82
+ }
83
+ }
84
+ /*
85
+ * Google Analytics Script Tag
86
+ */
87
+ function google_analytics_script() {
88
+ if( $this->should_track_visit() && ! get_option('ga_use_tag_manager') ) {
89
+ $GA_TRACKING_CODE = get_option('ga_tracking_code');
90
+ $ANONYMIZE_IP = get_option('ga_anonymize_ip');
91
+ ?>
92
+ <script>
93
+ if( !hasWKGoogleAnalyticsCookie() ) {
94
+ //Google Analytics
95
+ (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
96
+ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
97
+ m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
98
+ })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
99
+ ga('create', '<?php echo $GA_TRACKING_CODE; ?>', 'auto');
100
+ <?php
101
+ if( $ANONYMIZE_IP ) :
102
+ ?>
103
+ //anonymize IP
104
+ ga('set', 'anonymizeIp', true);
105
+ <?php
106
+ endif;
107
+ ?>
108
+ ga('send', 'pageview');
109
+ }
110
+ </script>
111
+ <?php
112
+ }
113
+ }
114
+
115
+ /*
116
+ * Load Text Domain
117
+ */
118
+ function load_textdomain() {
119
+ load_plugin_textdomain( 'wk-ga', false, dirname( plugin_basename(__FILE__) ) . '/lang/' );
120
+ }
121
+
122
+ /*
123
+ * Plugin Activation
124
+ */
125
+ public function activation() {
126
+
127
+ //set setting defaults
128
+ update_option( 'track_logged_in', false );
129
+ }
130
+
131
+ /*
132
+ * Plugin Deactivation
133
+ */
134
+ public function deactivation() {
135
+
136
+ //remove cookie
137
+
138
+ }
139
+
140
+ /*
141
+ * Register Settings
142
+ */
143
+ public function register_settings() {
144
+ register_setting(
145
+ 'wk_ga_google_analytics',
146
+ 'ga_tracking_code'
147
+ );
148
+
149
+ register_setting(
150
+ 'wk_ga_google_analytics',
151
+ 'track_logged_in'
152
+ );
153
+
154
+ register_setting(
155
+ 'wk_ga_google_analytics',
156
+ 'ga_anonymize_ip'
157
+ );
158
+
159
+ register_setting(
160
+ 'wk_ga_google_analytics',
161
+ 'ga_use_tag_manager'
162
+ );
163
+
164
+ register_setting(
165
+ 'wk_ga_google_analytics',
166
+ 'ga_tag_manager_id'
167
+ );
168
+
169
+ }
170
+
171
+ /*
172
+ *
173
+ */
174
+ public function load_admin_scripts( $hook ) {
175
+ if( $hook != "settings_page_google_analytics" ) {
176
+ return;
177
+ }
178
+
179
+ //admin styles
180
+ wp_enqueue_style( 'custom-admin-styles', plugin_dir_url( __FILE__ ) . '/css/admin-styles.css' );
181
+
182
+ //cookie library
183
+ wp_enqueue_script( 'cookie-js', plugin_dir_url( __FILE__ ) . '/js/js.cookie.js' );
184
+
185
+ //admin js for cookies
186
+ wp_register_script( 'wk-ga-admin-js', plugin_dir_url( __FILE__ ) . '/js/admin-functions.js', array('jquery', 'cookie-js') );
187
+
188
+ //translate JavaScript
189
+ $translation_array = array(
190
+ 'UntrackText' => __('Page visits from this device are not tracked.','wk-ga'),
191
+ 'TrackText' => __('This device is treated like any other','wk-ga')
192
+ );
193
+ wp_localize_script('wk-ga-admin-js', 'text_content', $translation_array );
194
+ wp_enqueue_script('wk-ga-admin-js');
195
+
196
+ }
197
+
198
+ /*
199
+ * Settings Page
200
+ */
201
+ public function settings_page() {
202
+ add_options_page(
203
+ 'Google Analytics',
204
+ 'Google Analytics',
205
+ 'manage_options',
206
+ 'google_analytics',
207
+ array( $this, "settings_content" )
208
+ );
209
+ }
210
+
211
+ public function settings_content() {
212
+ if ( ! isset( $_REQUEST['settings-updated'] ) )
213
+ $_REQUEST['settings-updated'] = false;
214
+ ?>
215
+ <div class="wrap">
216
+ <h2><?php echo esc_html( get_admin_page_title() ); ?></h2>
217
+
218
+ <?php if ( false !== $_REQUEST['settings-updated'] ) : ?>
219
+ <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>
220
+ </div>
221
+ <?php endif; ?>
222
+
223
+ <p><?php _e('Enter your Google Analytics tracking code below. You can also use Google Tag Manager instead by checking the relevant setting.', 'wk-ga'); ?>
224
+ </p>
225
+
226
+ <form id="wk-google-analytics-settings" method="post" action="options.php">
227
+ <?php settings_fields( 'wk_ga_google_analytics' ); ?>
228
+ <?php do_settings_sections('wk_ga_google_analytics'); ?>
229
+
230
+ <div class="use-google-analytics">
231
+ <label><?php _e('GA Tracking Code', 'wk-ga'); ?></label>
232
+ <input type="text" name="ga_tracking_code" value=<?php echo esc_attr( get_option( "ga_tracking_code" ) ); ?> />
233
+ </div>
234
+ <div class="use-google-analytics">
235
+ <label><?php _e("Anonymize IP's", 'wk-ga'); ?></label>
236
+ <input type="checkbox" name="ga_anonymize_ip" value="1" <?php checked( get_option( "ga_anonymize_ip") ); ?> />
237
+ </div>
238
+ <div>
239
+ <label><?php _e('Track logged in users', 'wk-ga'); ?></label>
240
+ <input type="checkbox" name="track_logged_in" value="1" <?php checked( get_option( "track_logged_in" ) ); ?> />
241
+ </div>
242
+ <div>
243
+ <label><?php _e("Use Google tag manager instead", 'wk-ga'); ?></label>
244
+ <input id="use-google-tag-manager" type="checkbox" name="ga_use_tag_manager" value="1" <?php checked( get_option( "ga_use_tag_manager") ); ?> />
245
+ </div>
246
+ <div class="use-google-tag-manager">
247
+ <label><?php _e("Google Tag Manager ID", 'wk-ga'); ?></label>
248
+ <input type="text" name="ga_tag_manager_id" value=<?php echo esc_attr( get_option( "ga_tag_manager_id" ) ); ?> />
249
+ </div>
250
+ <?php submit_button(); ?>
251
+ </form>
252
+ <div>
253
+ <div id="track-device"></div>
254
+ </div>
255
+ <!-- Begin MailChimp Signup Form -->
256
+ <div id="mc_embed_signup">
257
+ <form action="//webkinder.us12.list-manage.com/subscribe/post?u=979fe90d29c9ca9e25d5acc4b&amp;id=dfae840228" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>
258
+ <div id="mc_embed_signup_scroll">
259
+ <h2>Stay updated on our plugins</h2>
260
+ <div class="mc-field-group">
261
+ <label for="mce-EMAIL"><?php _e("Email Address", 'wk-ga'); ?><span class="asterisk">*</span>
262
+ </label>
263
+ <input type="email" value="" name="EMAIL" class="required email" id="mce-EMAIL">
264
+ </div>
265
+ <div class="mc-field-group">
266
+ <label for="mce-FNAME"><?php _e("First Name", "wk-ga"); ?></label>
267
+ <input type="text" value="" name="FNAME" class="" id="mce-FNAME">
268
+ </div>
269
+ <div class="mc-field-group">
270
+ <label for="mce-LNAME"><?php _e("Last Name", "wk-ga"); ?></label>
271
+ <input type="text" value="" name="LNAME" class="" id="mce-LNAME">
272
+ </div>
273
+ <div id="mce-responses" class="clear">
274
+ <div class="response" id="mce-error-response" style="display:none"></div>
275
+ <div class="response" id="mce-success-response" style="display:none"></div>
276
+ </div> <!-- real people should not fill this in and expect good things - do not remove this or risk form bot signups-->
277
+ <div style="position: absolute; left: -5000px;" aria-hidden="true"><input type="text" name="b_979fe90d29c9ca9e25d5acc4b_dfae840228" tabindex="-1" value=""></div>
278
+ <div class="clear"><input type="submit" value="Subscribe" name="subscribe" id="mc-embedded-subscribe" class="button button-primary"></div>
279
+ </div>
280
+ </form>
281
+ </div>
282
+ <!--End mc_embed_signup-->
283
+ </div>
284
+
285
+ <?php
286
+ }
287
+
288
+ }
289
+
290
+ $wk_ga = new wk_ga();
291
+
292
+ ?>