Mobile app version of vmapp.org
Login or Join
Cofer257

: How to create Google Analytics goal for anchor click to another website? I'm new to GA, I've got an anchor link set up on my website mysite.com, that leads users to another website site2.com.

@Cofer257

Posted in: #Anchor #GoalTracking #GoogleAnalytics

I'm new to GA, I've got an anchor link set up on my website mysite.com, that leads users to another website site2.com. Is it possible to set a goal in GA dashboard for a click on that anchor?

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Cofer257

2 Comments

Sorted by latest first Latest Oldest Best

 

@Sherry384

In order to track goals, you need to record the link click as something that GA can use to track goals. This can be done either by an event or virtual page view. Events are better, thanks to offered customization options.

To be sure that all your events will be send to GA before users leave your site, you can choose one of two options:

a) Modify the tracking code to use transport beacon, code sample:

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


Please note that this will work only in browsers that support navigator.sendBeacon:


If you specify 'beacon' and the user's browser does not support the
navigator.sendBeacon method, it will fall back to 'image' or 'xhr'
depending on hit size.


b) Use a callback function on interactions that you wish to track. Code sample:

// Gets a reference to the form element, assuming
// it contains the id attribute "signup-form".
var form = document.getElementById('signup-form');

// Adds a listener for the "submit" event.
form.addEventListener('submit', function(event) {

// Prevents the browser from submitting the form
// and thus unloading the current page.
event.preventDefault();

// Sends the event to Google Analytics and
// resubmits the form once the hit is done.
ga('send', 'event', 'Signup Form', 'submit', {
hitCallback: function() {
form.submit();
}
});
});


Side note:

There is also an interesting plugin from Google, called Autotrack. This plugin has eventTracker module, which allows you to code event tracking like this:

<button
ga-on="click"
ga-event-category="Video"
ga-event-action="play">
Play video
</button>

10% popularity Vote Up Vote Down


 

@Rambettina238

I would advise setting up event tracking on the link. Event tracking can be implemented with the following syntax for Google Universal Analytics

ga('send', 'event', [eventCategory], [eventAction], [eventLabel], [eventValue], [fieldsObject]);


This could be implemented on your site as:

<a href="site2.com" onclick="ga('send', 'event', 'Click', 'External Link Click', 'site2.com');">Link</a>

Once this is implemented on any links where you would want to set up the goal, you can set up a goal by selecting 'custom' goal and then 'event' as the type. then category:'Click', Action:'External Link Click', Label:'site2.com'.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme