You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 11, 2023. It is now read-only.
There are a lot of outbound links on the website and clicks on those are not tracked in google analytics. Because of that it is hard to understand if people are just leaving the website or going to e.g. project page.
If you have added the Analytics tracking code directly to your site, you can copy and paste the script below into your own pages to set up Event tracking for outbound links. You should add this script in your page header, but not within the basic Analytics tracking code snippet.
If you copy and paste this script exactly as it appears here, your outbound clicks will appear in your Analytics Events reports with a Category of "outbound" and an Action of "click". (In the snippet, these are shown in bold.) You can use these values, or change them and define your own values. Learn more about Event components.
This example assumes that you are using the analytics.js tracking code. See if you are using Classic Analytics (ga.js) or Universal Analytics (analytics.js).
<script>
/**
* Function that tracks a click on an outbound link in Analytics.
* This function takes a valid URL string as an argument, and uses that URL string
* as the event label. Setting the transport method to 'beacon' lets the hit be sent
* using 'navigator.sendBeacon' in browser that support it.
*/
var trackOutboundLink = function(url) {
ga('send', 'event', 'outbound', 'click', url, {
'transport': 'beacon',
'hitCallback': function(){document.location = url;}
});
}
</script>
You'll also need to add (or modify) the onclick attribute to your links. Use this example as a model for your own links:
<a href="http://www.example.com" onclick="trackOutboundLink('http://www.example.com'); return false;">Check out example.com</a>
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
There are a lot of outbound links on the website and clicks on those are not tracked in google analytics. Because of that it is hard to understand if people are just leaving the website or going to e.g. project page.
Suggestion: add tracking to outbound links. https://support.google.com/analytics/answer/1136920?hl=en
Adding tracking directly to your site
If you have added the Analytics tracking code directly to your site, you can copy and paste the script below into your own pages to set up Event tracking for outbound links. You should add this script in your page header, but not within the basic Analytics tracking code snippet.
If you copy and paste this script exactly as it appears here, your outbound clicks will appear in your Analytics Events reports with a Category of "outbound" and an Action of "click". (In the snippet, these are shown in bold.) You can use these values, or change them and define your own values. Learn more about Event components.
This example assumes that you are using the analytics.js tracking code. See if you are using Classic Analytics (ga.js) or Universal Analytics (analytics.js).
You'll also need to add (or modify) the onclick attribute to your links. Use this example as a model for your own links:
The text was updated successfully, but these errors were encountered: