Last active
December 13, 2016 13:59
Using data attributes to load Google Analytics.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- This is the BAD and ugly way! --> | |
<a href="{{baseurl}}something/" onclick="ofw.track('Something', 'click', 'Bad way')">Something</a> | |
<!-- This is the GOOD way! --> | |
<a href="{{baseurl}}something/" data-track-category="Something" data-track-label="Good way" class="goodway">Something</a> | |
Optionally you can add data-track-action (defaults to 'click') and data-track-value (defaults to empty). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Let's subscribe to a specific element | |
$('.goodway').on('ofw:track:trigger', function(event, category, action, label, value){ | |
// Do something here! | |
}); | |
// Let's subscribe to all read actions | |
$('[data-track-action="read"]').on('ofw:track:trigger', function(event, category, action, label, value){ | |
// Do something here! | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment