Plugin Directory

Changeset 1733426


Ignore:
Timestamp:
09/21/2017 05:40:09 AM (9 years ago)
Author:
ankurk91
Message:

trunk 1.4.1

Location:
ank-simplified-ga/trunk
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • ank-simplified-ga/trunk/ank-simplified-ga.php

    r1680828 r1733426  
    77 * Plugin URI: https://github.com/ankurk91/wp-google-analytics
    88 * Description: Simple, light weight, and non-bloated Google Analytics plugin for WordPress.
    9  * Version: 1.4.0
     9 * Version: 1.4.1
    1010 * Author: Ankur Kumar
    1111 * Author URI: https://ankurk91.github.io/
     
    1919if (!defined('ABSPATH')) exit;
    2020
    21 define('ASGA_PLUGIN_VER', '1.4.0');
     21define('ASGA_PLUGIN_VER', '1.4.1');
    2222define('ASGA_BASE_FILE', __FILE__);
    2323define('ASGA_OPTION_NAME', 'asga_options');
  • ank-simplified-ga/trunk/assets/front-end.js

    r1680828 r1733426  
    11(function (window, document) {
    2     'use strict';
     2  'use strict';
    33
    4     // Get dynamic options from page
    5     var asgaOpt = window._asgaOpt;
     4  // Get dynamic options from page
     5  var asgaOpt = window._asgaOpt;
    66
    7     document.addEventListener("DOMContentLoaded", function (event) {
     7  document.addEventListener("DOMContentLoaded", function (event) {
    88
    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|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, '|');
    1313
    14             // https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/RegExp
    15             var regExt = new RegExp(".*\\.(" + exts + ")(\\?.*)?$");
     14      // https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/RegExp
     15      var regExt = new RegExp(".*\\.(" + exts + ")(\\?.*)?$");
    1616
    17             var downLinks = document.querySelectorAll('a');
     17      var downLinks = document.querySelectorAll('a');
    1818
    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                     });
     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          });
    2525
    26                     // Only add download attribute if does not have
    27                     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', '');
    2929
    30                 }
    31             });
     30        }
     31      });
    3232
    33         }
     33    }
    3434
    35         // Track Mailto links
    36         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"]');
    3838
    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      });
    4545
    46         }
     46    }
    4747
    48         // Track Outbound Links
    49         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"]');
    5151
    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 tab
     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 tab
    5959
    60                 }
     60        }
    6161
    62             });
     62      });
    6363
    64         }
     64    }
    6565
    66     });
     66  });
    6767
    6868
    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;
     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;
    7979
    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');
    8283
    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  }
    97100
    98101})(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  
    11(function (window, jQuery) {
    2     'use strict';
    3     // Get requested tab from url
    4     var requestedTab = window.location.hash.replace('#top#', '');
     2  'use strict';
     3  // Get requested tab from url
     4  var requestedTab = window.location.hash.replace('#top#', '');
    55
    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');
     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');
    1313
    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);
     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);
    2121
    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         }));
     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    }));
    3535
    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     });
     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  });
    4747})(window, jQuery);
  • ank-simplified-ga/trunk/inc/class-admin.php

    r1680828 r1733426  
    22
    33namespace Ankur\Plugins\Ank_Simplified_GA;
    4 
    5 use Ankur\Plugins\Ank_Google_Map\Singleton;
    64
    75/**
  • ank-simplified-ga/trunk/inc/class-frontend.php

    r1680828 r1733426  
    33namespace Ankur\Plugins\Ank_Simplified_GA;
    44
    5 use Ankur\Plugins\Ank_Google_Map\Singleton;
    65
    76/**
  • ank-simplified-ga/trunk/readme.txt

    r1680828 r1733426  
    22Tags: google analytics, tracking, light weight, simple, easy, free, multi-site
    33Requires at least: 4.0.0
    4 Tested up to: 4.8.0
    5 Stable tag: 1.4.0
     4Tested up to: 4.8.2
     5Stable tag: 1.4.1
    66License: MIT
    77License URI: https://opensource.org/licenses/MIT
     
    184184== Changelog ==
    185185
    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 =
    187191* Compatible with WP v4.8.0
    188192* Remove: Option to load JS on `window.load` event
Note: See TracChangeset for help on using the changeset viewer.