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
// To get started, make sure you're using the latest version of the analytics.js snippet (4.1.0 or above) | |
// and remove the `analytics.load("YOUR_WRITE_KEY")` call. then drop this script below the snippet. | |
// this is a standalone script for modern browsers. if you'd like to target older browsers, include | |
// a fetch polyfill and use that instead of window.fetch. This would require that you build and package the | |
// script somehow (rollup, webpack, browserify, etc). You may also want to transpile it to ES5 w eg Babel. | |
// This script is configured to make all collection opt-in (rather than opt-out) for all users. | |
// If you want to conditionally require whether or not to block data collection before affirmative consent, use something | |
// like inEU below and pass that function into `conditionallyLoadAnalytics`. If you want to collect data until the user |
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
/** | |
* Steps to use: | |
* 1. Create CF Worker, copy and paste this in | |
* 2. (Optional) Update configuration defaults | |
* - If you want to manage in code, do so below under "Static Configuration" | |
* - If you want dynamic custom config: Create CFW KV namespace, link them, and add reference below | |
* | |
* - You can overwrite default path prefix for loading analytics.js (<yourdomain>/ajs) | |
* (corresponding KV entry: `script_path_prefix`) | |
* - You can overwrite default path prefix for handling first-party data collection (<yourdomain>/data) |
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
<script> | |
/** | |
* Provides a fake analytics object that sends all calls to the parent window for processing | |
*/ | |
var analytics = (function() { | |
var eventQueue = []; | |
// Send the events to the frame if it's ready. | |
function flush(method, args) { | |
while (eventQueue.length) { |
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
const PassThrough = require('stream').PassThrough; | |
const Router = require('koa-66'); | |
const router = new Router(); | |
const Koa = require('koa'); | |
const app = new Koa(); | |
// ... | |
const sse = (event, data) => { | |
return `event:${ event }\ndata: ${ data }\n\n` |
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
// https://segment.com/docs/connections/functions/destination-functions/ | |
export const track = insertEvent | |
export const identify = insertEvent | |
export const page = insertEvent | |
export const screen = insertEvent | |
export const group = insertEvent | |
// https://docs.rockset.com/rest-api/#patchdocuments | |
const insertEvent = async (msg, { collection, workspace, apiKey }) => { | |
const endpoint = `https://api.rs2.usw2.rockset.com/v1/orgs/self/ws/${workspace}/collections/${collection}/docs` |
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
async function track(e, settings) { | |
return await send(e, settings) | |
} | |
async function identify(e, settings) { | |
return await send(e, settings) | |
} | |
async function group(e, settings) { | |
return await send(e, settings) |
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
// adds a check (`g.auryc[fn] !== wrapper`) to prevent the recursion when auryc isn’t loaded yet | |
// fixed the usage of `arguments` | |
function safeInvoke(g, fn) { | |
return function wrapper() { | |
if (g.auryc && typeof g.auryc[fn] !== 'undefined' && g.auryc[fn] !== wrapper) { | |
g.auryc[fn].call(this, Array.prototype.slice.call(arguments, 0)); | |
} | |
else { | |
g.aurycReadyCb.push(function () { |
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
/** | |
* Pixel Loader. | |
* It will make the http request on construction, no need to dom insert. | |
*/ | |
const loadPixel = (src, fn=()=>{}) => ({ | |
...new Image, | |
onload() { fn() }, | |
height: 1, |
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
// on page with the payment/login button that they leave from | |
var link = document.getElementById('paymentOrLoginLinkElementID') | |
var href = link.getAttribute('href'); | |
link.addEventListener('click', function(event){ | |
// before progressing to the link, save the referrer | |
event.preventDefault(); | |
sessionStorage.setItem('ctxReferrer', document.referrer); | |
window.location.href = href; | |
}); |
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
/** | |
* helper function to take the form and | |
* get back a js object with field/value mappings | |
* ignoring submit fields and fields whose name we can't ascertain | |
*/ | |
function serialize(form){ | |
return Array.prototype.slice.call(form.elements) | |
.filter(isInputElement) | |
.filter(isNotSubmit) |
NewerOlder