URL Redirects

Redirects let you record events when a link is clicked, and then forwards the request to a given URL.

How Do I Use It?

There are three important parts to creating a URL redirect:

  1. The URL needs to include the name of the collection where you would like to store the click events. You can name it anything you want. Here’s an example URL if you wanted to track an event in a collection called link_clicked:
  1. The URL needs to include a query string parameter called data containing the base 64 encoded JSON string of the event you want to track. Here’s what your event JSON might look like prior to encoding it. Use any property names and any number of properties you want!
  "campaign": "Awesome analytics!",
  "recipient": "team@email.com"
  1. The URL should also include a redirect parameter containing the final destination of the request. After the event is recorded, the request will be forwarded to this URL.

Your link will look something like this:

<a href="https://api.keen.io/3.0/projects/PROJECT_ID/events/link_clicked?api_key=WRITE_KEY&data=ENCODED_DATA&redirect=http://my-site.com/actual-href">Click me!</a>

This would result in an event being written to the link_clicked collection!

If your redirect parameter includes &, remember to URL encode the full redirect URL and store the parameter before recording the event.