Google Analytics event tracking for external links

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

Hi @indiaserlin, thanks for the post.

First, I would signup for Google Tag Manager and setup your tracking to use Google Tag Manage code: About Google Tag Manager  |  Google for Developers (also see The Easy as Pie Guide to Installing Google Tag Manager)

And add code to your HEAD of the site using the quickstart guide: Google Tag Manager לדפי אינטרנט  |  Google Tag Manager for Web  |  Google for Developers

Here is how to add code to the HEAD: Custom code in head and body tags | Webflow University

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.

1 Like

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