Skip to content

Instantly share code, notes, and snippets.

@wei
Last active January 23, 2020 21:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wei/34de0d72ff13ba45cafda661fc0e0449 to your computer and use it in GitHub Desktop.
Save wei/34de0d72ff13ba45cafda661fc0e0449 to your computer and use it in GitHub Desktop.
Setup Google Analytics to track outbound links. Supports target="_blank".

Google Analytics Outbound Links Tracking

The official answer from Google does not support target="_blank" links and requires you to manually add code to each anchor link.

This solution handles all links on page and checks hostname and target automatically before adding onclick events.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment