/link

Serverless link tracking with Google Analytics

Primary LanguageJavaScript

link

Free client side link tracking with GitHub Pages & Google Analytics

Simply fork, configure, and create your own custom tracked links!

Example: My GitHub Profile

Google Analytics Dashboard

Setup

1. Create a Google Analytics account (if needed)

This step can be skipped if you already have an account. link tracking uses GA to collect and store data.

Instructions to Setup Google Analytics

2. Fork this repository

Make copy of this repo. link tracking uses GitHub Pages to collect data and redirect users.

How to Fork a Repo

3. Set your Google Analytics ID in the config field of link.js

Set the gaID field in link.js of your forked repo. This ID is used by Google to direct Analytics Events such as link clicks to your account.

const config = {
	gaID: 'UA-46933211-3', // CHANGE ME
	// ...
};

Analytics ID can be found in the Admin panel on Google Analytics.

How to Find Google Analytics ID

4. Set up GitHub Pages for your repo

GitHub Pages will serve the link tracking and forwarding repo for free!

How to Setup GitHub Pages for a Repository

5. All done!

Links can now be created using <username>.github.io/link/?l=<url>, and clicks can be viewed in the "Events" section of Google Analytics. To view in Realtime select "Realtime > Events" in the GA menu.

Github pages can be configured to a custom domain name - currently I use kevingleason.me/link), which allows creation of tracked links to have a custom name.

How to Setup a Custom Domain with GitHub Pages

Notes

This link tracking is as accurate as Google Analytics. If browsers block Google Analytics, the resulting clicks will not be accurately tracked. In these cases, the redirect will still work just fine after a 1-second timeout.