Code Monkey home page Code Monkey logo

arkadyan / aws-serverless-tracking-pixel Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aws-samples/aws-serverless-tracking-pixel

0.0 2.0 0.0 20 KB

This solution deploys a lambda function and an API Gateway HTTP API to process tracking information from the HTTP request, returning a 1x1 transparent pixel so it can be invoked from an IMG HTML tag. The processing AWS Lambda Function sends the parsed information to an Amazon Kinesis Data Firehose Stream that should already exist. This solution is created as a baseline to be modified so it adapts to the specific use-case, according to the incoming information that should be processed.

License: MIT No Attribution

Python 100.00%

aws-serverless-tracking-pixel's Introduction

aws-serverless-tracking-pixel

This solution deploys a lambda function and an API Gateway HTTP API to process tracking information from the HTTP request, returning a 1x1 transparent pixel so it can be invoked from an IMG HTML tag. The processing AWS Lambda Function sends the parsed information to an Amazon Kinesis Data Firehose Stream that should already exist. This solution is created as a baseline to be modified so it adapts to the specific use-case, according to the incoming information that should be processed.

Solution architecture

The solution is built on top of serverless components

Deploying the solution

This project is built using the AWS Serverless Application Model (SAM), a framework extending AWS CloudFormation syntax to easily define serverless components such as AWS Lambda functions or Amazon DynamoDB tables.

The following tools are required to deploy it:

The following resources act as a prerequisit:

  • Amazon Kinesis DataFirehose delivery stream: A delivery stream should already exist in the same account and the same region where the solution will be deployed

To build and deploy for the first time, run the following in your shell:

sam build --use-container
sam deploy --guided

The first command will build the source of your application. The second command will package and deploy your application to AWS, with a series of prompts. If you choose to save your choices to samconfig.toml, then you no longer will need to pass the --guided flag, as the SAM CLI will read your settings from it.

Template parameters

  • KinesisFirehoseARN: ARN of the Amazon Kinesis DataFirehose delivery stream where the processed information will be published to.
  • KinesisFirehoseStreamName: Stream name of the previous delivery stream.

Template output

  • TrackingPixelProcessingAPIURL: URL endpoint to send the tracking information to.

How to use

The Amazon Lambda Function code should be modified to parse the desired HTTP request information. The example implementation extracts 5 different fields:

  • date: Time field of the HTTP request context.
  • ip: x-forwarded-for field of the HTTP request context, as Amazon API Gateway will place the original requester IP in this field.
  • userAgent: user-agent field of the HTTP request context.
  • userId: Custom parameter expected on the query string, called 'userid'.
  • thirdPartyId: Custom parameter expected on the query string, called 'thirdpartyname'.

Once customized, you can directly begin tracking interactions from web pages or emails from an HTML IMG tag, or from any other event producer you might consider by generating HTTP-GET requests to the URL of the template output. As an example, this would be an HTTP call for the example implementation:

wget https://<your template output domain>?userid=aws_user&thirdpartyname=example.hightrafficwebsite.com”

Developing

You can build with the following command:

sam build --use-container

The function can be locally invoked using sam local invoke. The events directory contains test events that can be passed on the function invocation.

sam local invoke TrackingPixelProcessing --event events/event.json

aws-serverless-tracking-pixel's People

Contributors

amazon-auto avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.