Google Analytics Plugin With Auto Tracking - EasyGA

File Size: 627 KB
Views Total: 1057
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   
Google Analytics Plugin With Auto Tracking - EasyGA

The EasyGA jQuery plugin makes it easier to insert Google Analytics tracking code to your webpage with auto tracking support.

Supports Page views, Events, Custom dimensions, Virtual page views, and External links. All the options can be passed via HTML data attributes.

How to use it:

1. Insert the necessary jQuery library, GA analytics.js and the EasyGA plugin's JavaScript into the document.

<script src="//code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="//www.google-analytics.com/analytics.js"></script>
<script src="/build/easy-google-analytics.js"></script>

2. Initialize the plugin and insert your own Google Analytics tracking ID. That's it.

window._easyGA = new EasyGA('UA-TRACKING-ID-HERE');

3. Enable the event tracking on a specific element (e.g call to action button).

<button type="submit" 
        data-analytics="trackEvents" 
        data-analytics-category="category"
        data-anlaytics-action="action"
        data-analytics-label="label(optional)"
        data-analytics-target-selector="selector(optional)">
        Action Button
</button> 

4. Track virtual page views.

<div data-analytics="trackPageView" 
     data-url="https://www.jqueryscript.net">
     ...
</div> 

5. Set custom dimensions and metrics.

<meta data-analytics="customDimension" 
      data-id="dimensionId"
      data-value="dimensionValue"> 

This awesome jQuery plugin is developed by alphagov. For more Advanced Usages, please check the demo page or visit the official website.