Skip to content

Instantly share code, notes, and snippets.

@LouiseSteward
Created October 22, 2021 10:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LouiseSteward/5140e4d10a63f1367e9247b5e26a0692 to your computer and use it in GitHub Desktop.
Save LouiseSteward/5140e4d10a63f1367e9247b5e26a0692 to your computer and use it in GitHub Desktop.
Example of the monetization tracking code, for "The Economy"
/*jslint browser */
/*globals window */
// Use tracking pixels in an AWS S3 bucket to count visitors with web monetization
function ebMonetizationCounter() {
"use strict";
// First determine whether this is the beginning of a new session
let isContinuedSession = sessionStorage.getItem("isContinuedSession");
// If it is the beginning of a new session, let's log it
// so that we have a record of all new user sessions
if (isContinuedSession !== "true") {
sessionStorage.setItem("isContinuedSession", "true");
// Set up the tracking pixel information
let awsS3 = "https://monetization-images.s3.us-east-2.amazonaws.com/";
awsS3 = awsS3 + "the-economy/"
// Log it by loading the new user session tracking pixel
let visitImage = document.createElement("img");
visitImage.src = awsS3 + "all-visits/pixel.png";
document.body.append(visitImage);
// Now we count visitors with monetization
if (document.monetization !== undefined) {
// Log it by loading the monetization tracking pixel
let monetizationImage = document.createElement("img");
monetizationImage.src = awsS3 + "monetization/pixel.png";
document.body.append(monetizationImage);
}
}
}
// Wait for the monetization extension to load
setTimeout(ebMonetizationCounter, 10000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment