Skip to content

Instantly share code, notes, and snippets.

@gthayer
Last active February 12, 2018 02:41
Show Gist options
  • Save gthayer/320dd8e68d40217bb748 to your computer and use it in GitHub Desktop.
Save gthayer/320dd8e68d40217bb748 to your computer and use it in GitHub Desktop.
Google Analytics Plugin Wrapper
//Load GA Plugin. If unable to load, wait 50 milliseconds and attempt load again.
function providePlugin(pluginName, pluginConstructor) {
if (window.ga && document.body ) {
ga('provide', pluginName, pluginConstructor);
}
else {
window.setTimeout(function() {
providePlugin('main_analytics', gaEventsLoader);
},
50);
}
}
// Plugin constructor.
function gaEventsLoader() {
//GA Plugin goes here
//__gaTracker( 'send', 'event', 'Category', 'Action', 'Label', 'Value', {'nonInteraction': 1} );
}
// Register the plugin.
providePlugin('main_analytics', gaEventsLoader);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment