2.0.12 • Published 2 years ago

@pinegraph/analytics-proxy-cdk-constructs v2.0.12

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
2 years ago

Analytics Proxy Constructs

What is this?

This package is an AWS CDK construct for creating a proxy over popular analytics frameworks. It creates a simple API Gateway endpoint that proxies to an analytics service and an S3 bucket to host a modified script.

AWS CDK enables people to have infrastructure as code (IAC). That is, with just a few commands, you'll have a fully running and functional production ready service in the cloud.

Problem

Ad blocking frameworks prevent analytics from being collected for popular frameworks like Google Analytics and Meta Pixel Events. While we should always value the user's privacy, we often have uses cases where we need to collect metrics on the site to improve it and find bugs. More often than not, re-inventing a solution results in less security, less features, less privacy, and more bugs.

Benefits

By using this proxy, you'll be able to get all metrics more accurately and cheaply than other solutions. The first 1 million API Gateway requests are free and is around $3.50 for each subsequent million requests.

Setup

  1. This package assummes that you are familiar with AWS CDK and already have a CDK app created. If not, follow this tutorial.
  2. Once you have a CDK app ready, create a new stack or modify an existing one to include the GoogleAnalyticsProxyConstruct. See the Example CDK App Code below.
  3. Deploy your change via cdk deploy.
  4. Go to your newly created or modified Cloudformation stack and look for the output value of *AnalyticsProxyGoogleAnalyticsSnippet*. For instance, if you are using GoogleAnalyticsProxy, you should see an output of with a key similar to GoogleAnalyticsProxyGoogleAnalyticsSnippet5ACCDD73 with a value similar to <script async src="https://websiteapis-googleanalyticsproxygooglegtagscriptc-6m06wqo0fty0.s3.amazonaws.com/gtag.js"></script>.
  5. Add the output to your website in the head tag.

Example CDK App Code

import { App, Stack, StackProps } from "aws-cdk-lib";
import { Construct } from "constructs";

const app = new App();

export class ExampleStack extends Stack {
  constructor(app: Construct, name: string, props: StackProps) {
    super(app, name, props);
    new GoogleAnalyticsProxyConstruct(this, "GoogleAnalyticsProxy", {
      gtmID: "G-EXAMPLETAG",
    });
  }
}
new ExampleStack(app, "ExampleStack", {
  env: {
    account: "1111-1111-1111-1111", // AWS Account ID
    region: "us-east-1", // AWS Region
  },
});
app.synth();

Questions?

Reach out to us on discord.

Releasing

  1. npm run build
  2. npm publish --access public
2.0.12

2 years ago

2.0.11

2 years ago

2.0.10

2 years ago

2.0.9

2 years ago

2.0.8

2 years ago

2.0.7

2 years ago

2.0.6

2 years ago

2.0.5

2 years ago

2.0.4

2 years ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago