Avoid the arduous process of using Google Tag Manager and Macros: handle Google Analytics Event Tracking via data attributes in your HTML.
- Include after you have instantiated the
ga( 'create' , 'UA-XXXX-Y' )method. - Add the class names you wish to track to the
_trackobject, or add.ga-trackto your elements - Populate the data-attributes on the HTML elements you wish to track
- Use on any
aelement, or add anhrefattribute to any other element and have the plugin treat it as ana.
<a href="/signup/confirm/" class="ga-track"
data-ec="Website Signups"
data-ea="Confirmed Signup"
data-el="Internal Form Submission"
data-ev="10">
| Attribute | Field Name | Link |
|---|---|---|
| data-ec | eventCategory | Google Documentation |
| data-ea | eventAction | Google Documentation |
| data-el | eventLabel | Google Documentation |
| data-ev | eventValue | Google Documentation |
- Remove jQuery dependency
- Comment properly
- Implement Promises before navigating the user