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?


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'.

  • It is more complicated than that. Even tracking fires off to Google Analytics asynchronously. When clicking a link, the page often gets unloaded before the event can fire and the data is not then recorded in Google Analytics. Nov 17 '16 at 11:06

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.

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

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:

  Play video

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.