Streaming live at 10am (PST)

Google Analytics event tracking for external links


#1

Hello, does anyone know what custom code to use to push notifications to google analytics every time an external link is clicked on my site?

I tried the code below (which doesn’t work) and as I have no coding background it isn’t really a surprise.

< script >

ga(‘create’, ‘UA-111279467-1’, ‘auto’);
ga(‘require’, ‘linkTracker’);
ga(‘send’, ‘pageview’);

< /script >

< script async src="/path/to/link-tracker-plugin.js">

function handleOutboundLinkClicks(event) {
ga(‘send’, ‘event’, {
eventCategory: ‘Outbound Link’,
eventAction: ‘click’,
eventLabel: event.target.href,
transport: ‘beacon’
});
}

< /script >

Any help would be much appreciated!

https://preview.webflow.com/preview/unwrapd?preview=9bd9e585bdb226560b55db211e1d180b


#2

Hi @indiaserlin, thanks for the post.

First, I would signup for Google Tag Manager and setup your tracking to use Google Tag Manage code: https://developers.google.com/tag-manager/ (also see https://www.crazyegg.com/blog/easy-google-tag-manager/)

And add code to your HEAD of the site using the quickstart guide: https://developers.google.com/tag-manager/quickstart

Here is how to add code to the HEAD: https://university.webflow.com/article/how-to-add-custom-head-and-body-code-to-a-webflow-site

Then, drag and embed widget on to the page, just under the Body tag and paste the code that goes in the body there:

After those things are set, then you can enable Google Event Tracking.

I would probably start with getting Google Tag Manager installed first, then move on to getting the tracking events created.


#3

This topic was automatically closed after 60 days. New replies are no longer allowed.