Created
October 22, 2021 10:36
-
-
Save LouiseSteward/5140e4d10a63f1367e9247b5e26a0692 to your computer and use it in GitHub Desktop.
Example of the monetization tracking code, for "The Economy"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*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