Changeset 1733426
- Timestamp:
- 09/21/2017 05:40:09 AM (9 years ago)
- Location:
- ank-simplified-ga/trunk
- Files:
-
- 2 added
- 7 edited
-
README.md (added)
-
ank-simplified-ga.php (modified) (2 diffs)
-
assets/front-end.js (modified) (1 diff)
-
assets/front-end.min.js (modified) (1 diff)
-
assets/option-page.js (modified) (1 diff)
-
inc/class-admin.php (modified) (1 diff)
-
inc/class-frontend.php (modified) (1 diff)
-
inc/class-singleton.php (added)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
ank-simplified-ga/trunk/ank-simplified-ga.php
r1680828 r1733426 7 7 * Plugin URI: https://github.com/ankurk91/wp-google-analytics 8 8 * Description: Simple, light weight, and non-bloated Google Analytics plugin for WordPress. 9 * Version: 1.4. 09 * Version: 1.4.1 10 10 * Author: Ankur Kumar 11 11 * Author URI: https://ankurk91.github.io/ … … 19 19 if (!defined('ABSPATH')) exit; 20 20 21 define('ASGA_PLUGIN_VER', '1.4. 0');21 define('ASGA_PLUGIN_VER', '1.4.1'); 22 22 define('ASGA_BASE_FILE', __FILE__); 23 23 define('ASGA_OPTION_NAME', 'asga_options'); -
ank-simplified-ga/trunk/assets/front-end.js
r1680828 r1733426 1 1 (function (window, document) { 2 'use strict';2 'use strict'; 3 3 4 // Get dynamic options from page5 var asgaOpt = window._asgaOpt;4 // Get dynamic options from page 5 var asgaOpt = window._asgaOpt; 6 6 7 document.addEventListener("DOMContentLoaded", function (event) {7 document.addEventListener("DOMContentLoaded", function (event) { 8 8 9 // Track Downloads10 if (asgaOpt.downloadLinks === '1') {11 // https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions12 var exts = (asgaOpt.downloadExt === '') ? 'doc*|xls*|ppt*|pdf|zip|rar|exe|mp3' : asgaOpt.downloadExt.replace(/,/g, '|');9 // Track Downloads 10 if (asgaOpt.downloadLinks === '1') { 11 // https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions 12 var exts = (asgaOpt.downloadExt === '') ? 'doc*|xls*|ppt*|pdf|zip|rar|mp3' : asgaOpt.downloadExt.replace(/,/g, '|'); 13 13 14 // https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/RegExp15 var regExt = new RegExp(".*\\.(" + exts + ")(\\?.*)?$");14 // https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/RegExp 15 var regExt = new RegExp(".*\\.(" + exts + ")(\\?.*)?$"); 16 16 17 var downLinks = document.querySelectorAll('a');17 var downLinks = document.querySelectorAll('a'); 18 18 19 Array.prototype.forEach.call(downLinks, function (link) {20 // Include only internal links for downloads21 if (link.hostname && (link.hostname === window.location.hostname) && link.href.match(regExt)) {22 link.addEventListener('click', function (e) {23 logClickEvent('Downloads', this.href, e)24 });19 Array.prototype.forEach.call(downLinks, function (link) { 20 // Include only internal links for downloads 21 if (link.hostname && (link.hostname === window.location.hostname) && link.href.match(regExt)) { 22 link.addEventListener('click', function (e) { 23 logClickEvent('Downloads', this.href, e) 24 }); 25 25 26 // Only add download attribute if does not have27 if (!link.hasAttribute('download'))28 link.setAttribute('download', '');26 // Only add download attribute if does not have 27 if (!link.hasAttribute('download')) 28 link.setAttribute('download', ''); 29 29 30 }31 });30 } 31 }); 32 32 33 }33 } 34 34 35 // Track Mailto links36 if (asgaOpt.mailLinks === '1') {37 var mailLinks = document.querySelectorAll('a[href^="mailto"]');35 // Track Mailto links 36 if (asgaOpt.mailLinks === '1') { 37 var mailLinks = document.querySelectorAll('a[href^="mailto"]'); 38 38 39 Array.prototype.forEach.call(mailLinks, function (link) {40 link.addEventListener('click', function (e) {41 // Label should not include 'mailto'42 logClickEvent('Email', this.href.replace(/^mailto\:/i, '').toLowerCase(), e)43 })44 });39 Array.prototype.forEach.call(mailLinks, function (link) { 40 link.addEventListener('click', function (e) { 41 // Label should not include 'mailto' 42 logClickEvent('Email', this.href.replace(/^mailto\:/i, '').toLowerCase(), e) 43 }) 44 }); 45 45 46 }46 } 47 47 48 // Track Outbound Links49 if (asgaOpt.outgoingLinks === '1') {50 var outLinks = document.querySelectorAll('a[href^="http"]');48 // Track Outbound Links 49 if (asgaOpt.outgoingLinks === '1') { 50 var outLinks = document.querySelectorAll('a[href^="http"]'); 51 51 52 Array.prototype.forEach.call(outLinks, function (link) {53 // https://css-tricks.com/snippets/jquery/target-only-external-links/54 if (link.hostname && link.hostname !== window.location.hostname) {55 link.addEventListener('click', function (e) {56 logClickEvent('Outbound', (asgaOpt.outboundLinkType === '1') ? this.hostname : this.href, e);57 });58 link.setAttribute('target', '_blank'); // make sure these links open in new tab52 Array.prototype.forEach.call(outLinks, function (link) { 53 // https://css-tricks.com/snippets/jquery/target-only-external-links/ 54 if (link.hostname && link.hostname !== window.location.hostname) { 55 link.addEventListener('click', function (e) { 56 logClickEvent('Outbound', (asgaOpt.outboundLinkType === '1') ? this.hostname : this.href, e); 57 }); 58 link.setAttribute('target', '_blank'); // make sure these links open in new tab 59 59 60 }60 } 61 61 62 });62 }); 63 63 64 }64 } 65 65 66 });66 }); 67 67 68 68 69 /**70 * Detect Analytics type and send event71 * @ref https://support.google.com/analytics/answer/103306872 * @param category string73 * @param label string74 * @param event click event75 */76 function logClickEvent(category, label, event) {77 // return early if event.preventDefault() was ever called on this event object.78 if (event.defaultPrevented) return;69 /** 70 * Detect Analytics type and send event 71 * @ref https://support.google.com/analytics/answer/1033068 72 * @param category string 73 * @param label string 74 * @param event click event 75 */ 76 function logClickEvent(category, label, event) { 77 // Return early if event.preventDefault() was ever called on this event object. 78 if (event.defaultPrevented) return; 79 79 80 // if label is not set then exit 81 if (typeof label === 'undefined' || label === '') return; 80 // If label is not set then exit 81 if (typeof label === 'undefined' || label === '') return; 82 var nonInteractive = (asgaOpt.nonInteractive === '1'); 82 83 83 if (window.ga && ga.hasOwnProperty('loaded') && ga.loaded === true && ga.create) { 84 // Universal event tracking 85 // https://developers.google.com/analytics/devguides/collection/analyticsjs/events 86 ga('send', 'event', category, 'click', label, { 87 nonInteraction: (asgaOpt.nonInteractive === '1') 88 }); 89 } else if (window._gaq && _gaq._getAsyncTracker) { 90 // Classic event tracking 91 // https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide 92 _gaq.push(['_trackEvent', category, 'click', label, 1, (asgaOpt.nonInteractive === '1')]); 93 } else { 94 (window.console) ? console.info('Google analytics not loaded yet.') : null 95 } 96 } 84 if (window.ga && ga.hasOwnProperty('loaded') && ga.loaded === true && ga.create) { 85 // Universal event tracking 86 // https://developers.google.com/analytics/devguides/collection/analyticsjs/events 87 ga('send', 'event', category, 'click', label, 1, 88 { 89 nonInteraction: nonInteractive 90 } 91 ); 92 } else if (window._gaq && _gaq._getAsyncTracker) { 93 // Classic event tracking 94 // https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide 95 _gaq.push(['_trackEvent', category, 'click', label, 1, nonInteractive]); 96 } else { 97 (window.console) ? console.info('Google analytics not loaded yet.') : null 98 } 99 } 97 100 98 101 })(window, document); -
ank-simplified-ga/trunk/assets/front-end.min.js
r1680828 r1733426 1 !function(t,e){"use strict";function n(e,n,a){ a.defaultPrevented||"undefined"!=typeof n&&""!==n&&(t.ga&&ga.hasOwnProperty("loaded")&&ga.loaded===!0&&ga.create?ga("send","event",e,"click",n,{nonInteraction:"1"===o.nonInteractive}):t._gaq&&_gaq._getAsyncTracker?_gaq.push(["_trackEvent",e,"click",n,1,"1"===o.nonInteractive]):t.console?console.info("Google analytics not loaded yet."):null)}var o=t._asgaOpt;e.addEventListener("DOMContentLoaded",function(){if("1"===o.downloadLinks){var a=""===o.downloadExt?"doc*|xls*|ppt*|pdf|zip|rar|exe|mp3":o.downloadExt.replace(/,/g,"|"),r=new RegExp(".*\\.("+a+")(\\?.*)?$"),i=e.querySelectorAll("a");Array.prototype.forEach.call(i,function(e){e.hostname&&e.hostname===t.location.hostname&&e.href.match(r)&&(e.addEventListener("click",function(t){n("Downloads",this.href,t)}),e.hasAttribute("download")||e.setAttribute("download",""))})}if("1"===o.mailLinks){var c=e.querySelectorAll('a[href^="mailto"]');Array.prototype.forEach.call(c,function(t){t.addEventListener("click",function(t){n("Email",this.href.replace(/^mailto\:/i,"").toLowerCase(),t)})})}if("1"===o.outgoingLinks){var l=e.querySelectorAll('a[href^="http"]');Array.prototype.forEach.call(l,function(e){e.hostname&&e.hostname!==t.location.hostname&&(e.addEventListener("click",function(t){n("Outbound","1"===o.outboundLinkType?this.hostname:this.href,t)}),e.setAttribute("target","_blank"))})}})}(window,document);1 !function(t,e){"use strict";function n(e,n,a){if(!a.defaultPrevented&&"undefined"!=typeof n&&""!==n){var r="1"===o.nonInteractive;t.ga&&ga.hasOwnProperty("loaded")&&ga.loaded===!0&&ga.create?ga("send","event",e,"click",n,1,{nonInteraction:r}):t._gaq&&_gaq._getAsyncTracker?_gaq.push(["_trackEvent",e,"click",n,1,r]):t.console?console.info("Google analytics not loaded yet."):null}}var o=t._asgaOpt;e.addEventListener("DOMContentLoaded",function(){if("1"===o.downloadLinks){var a=""===o.downloadExt?"doc*|xls*|ppt*|pdf|zip|rar|mp3":o.downloadExt.replace(/,/g,"|"),r=new RegExp(".*\\.("+a+")(\\?.*)?$"),i=e.querySelectorAll("a");Array.prototype.forEach.call(i,function(e){e.hostname&&e.hostname===t.location.hostname&&e.href.match(r)&&(e.addEventListener("click",function(t){n("Downloads",this.href,t)}),e.hasAttribute("download")||e.setAttribute("download",""))})}if("1"===o.mailLinks){var l=e.querySelectorAll('a[href^="mailto"]');Array.prototype.forEach.call(l,function(t){t.addEventListener("click",function(t){n("Email",this.href.replace(/^mailto\:/i,"").toLowerCase(),t)})})}if("1"===o.outgoingLinks){var c=e.querySelectorAll('a[href^="http"]');Array.prototype.forEach.call(c,function(e){e.hostname&&e.hostname!==t.location.hostname&&(e.addEventListener("click",function(t){n("Outbound","1"===o.outboundLinkType?this.hostname:this.href,t)}),e.setAttribute("target","_blank"))})}})}(window,document); -
ank-simplified-ga/trunk/assets/option-page.js
r1680828 r1733426 1 1 (function (window, jQuery) { 2 'use strict';3 // Get requested tab from url4 var requestedTab = window.location.hash.replace('#top#', '');2 'use strict'; 3 // Get requested tab from url 4 var requestedTab = window.location.hash.replace('#top#', ''); 5 5 6 jQuery(function ($) {7 /**8 * Cache DOM elements for later use9 */10 var $gaTabs = $('h2#ga-tabs'),11 $input = $("form#asga_form").find('input:hidden[name="_wp_http_referer"]'),12 $sections = $('section.tab-content');6 jQuery(function ($) { 7 /** 8 * Cache DOM elements for later use 9 */ 10 var $gaTabs = $('h2#ga-tabs'), 11 $input = $("form#asga_form").find('input:hidden[name="_wp_http_referer"]'), 12 $sections = $('section.tab-content'); 13 13 14 // If there no active tab found , set first tab as active15 if (requestedTab === '' || $('#' + requestedTab).length === 0) requestedTab = $sections.attr('id');16 // Notice: we are not using cached DOM in next line17 $('#' + requestedTab).addClass('active');18 $('#' + requestedTab + '-tab').addClass('nav-tab-active');19 // Set return tab on page load20 setRedirectURL(requestedTab);14 // If there no active tab found , set first tab as active 15 if (requestedTab === '' || $('#' + requestedTab).length === 0) requestedTab = $sections.attr('id'); 16 // Notice: we are not using cached DOM in next line 17 $('#' + requestedTab).addClass('active'); 18 $('#' + requestedTab + '-tab').addClass('nav-tab-active'); 19 // Set return tab on page load 20 setRedirectURL(requestedTab); 21 21 22 // Bind a click event to all tabs23 $gaTabs.find('a.nav-tab').on('click.asga', (function (e) {24 e.stopPropagation();25 // Hide all tabs26 $gaTabs.find('a.nav-tab').removeClass('nav-tab-active');27 $sections.removeClass('active');28 // Activate only clicked tab29 var id = $(this).attr('id').replace('-tab', '');30 $('#' + id).addClass('active');31 $(this).addClass('nav-tab-active');32 // Set return tab url33 setRedirectURL(id);34 }));22 // Bind a click event to all tabs 23 $gaTabs.find('a.nav-tab').on('click.asga', (function (e) { 24 e.stopPropagation(); 25 // Hide all tabs 26 $gaTabs.find('a.nav-tab').removeClass('nav-tab-active'); 27 $sections.removeClass('active'); 28 // Activate only clicked tab 29 var id = $(this).attr('id').replace('-tab', ''); 30 $('#' + id).addClass('active'); 31 $(this).addClass('nav-tab-active'); 32 // Set return tab url 33 setRedirectURL(id); 34 })); 35 35 36 /**37 * Set redirect url into form's input:hidden38 * Note: Using hardcoded plugin option page slug39 * @param url String40 */41 function setRedirectURL(url) {42 var split = $input.val().split('?', 1);43 //Update the tab id in last while keeping base url same44 $input.val(split[0] + '?page=asga_options_page#top#' + url);45 }46 });36 /** 37 * Set redirect url into form's input:hidden 38 * Note: Using hardcoded plugin option page slug 39 * @param url String 40 */ 41 function setRedirectURL(url) { 42 var split = $input.val().split('?', 1); 43 //Update the tab id in last while keeping base url same 44 $input.val(split[0] + '?page=asga_options_page#top#' + url); 45 } 46 }); 47 47 })(window, jQuery); -
ank-simplified-ga/trunk/inc/class-admin.php
r1680828 r1733426 2 2 3 3 namespace Ankur\Plugins\Ank_Simplified_GA; 4 5 use Ankur\Plugins\Ank_Google_Map\Singleton;6 4 7 5 /** -
ank-simplified-ga/trunk/inc/class-frontend.php
r1680828 r1733426 3 3 namespace Ankur\Plugins\Ank_Simplified_GA; 4 4 5 use Ankur\Plugins\Ank_Google_Map\Singleton;6 5 7 6 /** -
ank-simplified-ga/trunk/readme.txt
r1680828 r1733426 2 2 Tags: google analytics, tracking, light weight, simple, easy, free, multi-site 3 3 Requires at least: 4.0.0 4 Tested up to: 4.8. 05 Stable tag: 1.4. 04 Tested up to: 4.8.2 5 Stable tag: 1.4.1 6 6 License: MIT 7 7 License URI: https://opensource.org/licenses/MIT … … 184 184 == Changelog == 185 185 186 * 1.4.0 = 186 = 1.4.1 = 187 * Fix: send `1` as value in events 188 * Fix: php namespace 189 190 = 1.4.0 = 187 191 * Compatible with WP v4.8.0 188 192 * Remove: Option to load JS on `window.load` event
Note: See TracChangeset
for help on using the changeset viewer.