Skip to content
Demo implementation of a click tracking redirector
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


This is a simple implementation of a click tracking webserver, using cryptographically secured URLs.

It is part of this series of blog posts.


Usage of clicktrack:
  -config string
    	Use this configuration file (default "clicktrack-conf.json")
    	Create a new url, using key=value parameters or json on stdin
    	Create a new configuration file
  -parse string
    	Parse a redirector URL
    	Rotate the secret keys
    	Run a redirecting webserver

The first time it is run clicktrack will create a configuration file, clicktrack-conf.json, with sensible defaults in the current directory.

Generate a tracking url

$ clicktrack -create url= myid=steve

This will take a list of key=value pairs on the command line and print a tracking URL starting with the BaseURL configuration setting that embeds those values.

It must contain a url value, which is the destination that the link will redirect to. It may contain a slug value, which will be included in the link as readable text.

If no key=value pairs are provided it will read the same data as json on stdin.

Decoding a tracking URL

$ clicktrack -parse ...
  "myid": "steve",
  "url": ""

This takes a tracking URL that had previously been generated and decodes it, showing the original parameters passed as json.

Running a redirector server

$ clicktrack -serve
Listening on

This will run a webserver on the address and port in the Listen parameter in the configuration file.

It will answer requests for tracking URLs, returning a redirect for valid ones and a 404 response in the case of any error. It will print the parameters as json to stdout for each request.

You can use curl -D- from another window to see exactly how it responds, or enter a tracking URL into your regular browser to see it work.

Rotating keys

$ clicktrack -rotate

This is an example of how to switch to a new signing key (and potentially an entirely new protocol). It increases the Version field in the configuration file and generates a matching signing key. It doesn't delete older keys, so previously generated URLs will continue to work.


It's a simple Go application that only uses the standard library

git clone
cd clicktrack
go build
You can’t perform that action at this time.