Skip to content

Instantly share code, notes, and snippets.

@BaileySimrell
Created December 4, 2019 23:28
Show Gist options
  • Save BaileySimrell/f62133c558c7f5364142c935c0101ed2 to your computer and use it in GitHub Desktop.
Save BaileySimrell/f62133c558c7f5364142c935c0101ed2 to your computer and use it in GitHub Desktop.
paste this code in the footer of your site's settings within Webflow to send event data to GA from Webflow attributes
<!-- Start of Google Analytics Event tracking code -->
<script>
$(document).ready(function() {
$(document).on('click', '[data-gatrack]', function(e) {
var $link = $(this);
var commaSeperatedEventData = $link.data('gatrack');
var eventParams = commaSeperatedEventData.split(',');
if (!eventParams) { return; }
eventCategory = eventParams[0]
eventAction = eventParams[1]
eventLabel = eventParams[2]
gtag(
'event',
eventAction,
{
'event_category': eventCategory,
'event_label': eventLabel
}
)
});
});
</script>
<!-- End of Google Analytics Event tracking code -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment