Make your own pixel tracker with AWS Kinesis Firehose and AWS Redshift

Jongleberry
Jan 2, 2017 · 10 min read

What are tracking pixels

<img src="https://analytics.example.com/1x1.gif?event=load" hidden>
https://analytics.example.com/1x1.gif?event=[EVENT]
function callWebBeacon(url, event) {
url = url.replace(/\[EVENT\]/ig, event)
const img = new Image()
img.src = url
img.style.display = 'none'
document.body.appendChild(img)
}

What is AWS Kinesis Firehose and Redshift?

Creating your Redshift database

Creating your Redshift table

CREATE TABLE events (
id VARCHAR(36) NOT NULL PRIMARY KEY,
event VARCHAR(20) NOT NULL DISTKEY,
received_at TIMESTAMP NOT NULL SORTKEY
);

Creating your Kinesis Firehose

FORMAT AS JSON 'AUTO' GZIP TRUNCATECOLUMNS MAXERROR 100000

Tracking load errors

Creating your tracking server

Calling your pixels

import { stringify } from query-string'function track(data) {
const img = new Image()
img.src = 'https://analytics.example.com?' + stringify(data)
img.style.display = 'none'
document.body.appendChild(img)
}

Maintaining your database

VACUUM FULL;

Manage query workloads

Whether to use AWS API Gateway

Conclusion

Jongleberry

Written by

Facial Contortionist

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade