Skip to content

Instantly share code, notes, and snippets.

View simone-coelho's full-sized avatar

Simone Coelho simone-coelho

View GitHub Profile
@simone-coelho
simone-coelho / bucketing_script.js
Last active September 17, 2021 18:49 — forked from thegreekjester/bucketing_script.js
Bucketing script given input CSV
/*
Install required libraries:
- yargs (CLI)
- fast-csv (csv parser and writer)
- @optimizely/optimizely-sdk (optimizely SDK)
The following script takes in the following CLI arguments:
sdkKey (str): SDK Key of Optimizely datafile you wish to use
csv_file_path (str): The input CSV relative path with the following columns --> "User Identifier", "Bucketing ID",
@simone-coelho
simone-coelho / experiment.ts
Created April 19, 2021 23:39 — forked from athal7/experiment.ts
2u lambda edge implementation
import optimizely from '@optimizely/optimizely-sdk'
import optimizelyLogging from '@optimizely/optimizely-sdk/lib/plugins/logger'
import optimizelyEnums from '@optimizely/optimizely-sdk/lib/utils/enums'
import cookie from 'cookie'
import rp from 'request-promise'
import uuidv4 from 'uuid/v4'
import {
Callback,
Handler,
CloudFrontRequest,
let axios = require("axios");
let argv = require("yargs").argv;
let s3 = require("@auth0/s3");
let fs = require("fs");
let path = require("path");
// let parquet = require('node-parquet');
let appDir = path.dirname(require.main.filename);
let decisionsFiles = [];
let eventsFiles = [];
//require('s3-upload-resume');
// BEGIN: Initialize Optimizely Event Push
function dispatchOptimizelyEvent(payload, eventID, eventKey) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4) { // request finished and response is ready
if(xmlhttp.status == 204) {
console.log('Fired event to Optimizely: ', eventKey);
} else {
console.log('Failed to dispatch Optimizely event: ', xmlhttp.responseText);
}
@simone-coelho
simone-coelho / project.js
Last active August 20, 2020 19:57 — forked from davidsertillange-optimizely/project.js
Mirroring Web events in Full Stack
/*
How to use:
Step 1: line 20-26, enter account_id, project_id, Full Stack user_id, environmentKey, and updateDatafile
Step 2: make sure your Full Stack project has the events you want to mirror created.
The API names need to match between the Web and Full Stack events.
Example: on Web, i have a click event "Homepage clicks" with API name "123456790_homepage_clicks"
In the Full Stack project, a custom event with the same name "123456790_homepage_clicks" needs to be created for this script to work
Step 3: add the script to Project Javascript
Step 4: load your page and check the network tab for events going to /events with "client_name": "Optimizely/fswebintegration"
@simone-coelho
simone-coelho / X_JS_API_Get_Campaigns_Audiences.js
Last active November 22, 2017 03:10
X_JS_API_Get_Campaigns_Audiences
/*output is a concatenated string for testing, but feel free to reformat as needed*/
/*campaignID:experimentId:variationId:audienceId:"audience conditions"*/
/*e.g. 7807482864:7807902575:7806347946:6536242902:"and,or,or,{"value":"iphone","type":"device","name":null,"match":null}",7807482864:7807902575:7806347946:9436482444:"and,or,or,{"value":"00:00_23:59_friday","type":"time_and_day","name":null,"match":null}"*/
/*this code only includes audiences for which the visitor actually qualified*/
var state = window.optimizely.get && window.optimizely.get('state');
var data = window.optimizely.get && window.optimizely.get('data');
(function getCurrentActiveAll(e) {
if ('undefined' !== typeof window.optimizely) {