Skip to content

Instantly share code, notes, and snippets.

View Segment Optimizely Lambda.js
// Learn more about destination functions API at
// https://segment.com/docs/connections/destinations/destination-functions
/**
* Handle track event
* @param {SegmentTrackEvent} event
* @param {FunctionSettings} settings
*/
async function onTrack(event, settings) {
//1. Get Datafile
View Heap basic sample
var heapDecision = function(decision) {
var type = decision.type
if (type == "feature") {
var info = decision.decisionInfo;
var featureKeyString = "[Optimizely Feature] " + info.featureKey;
var enabled = info.featureEnabled;
heap.addUserProperties(
{featureKeyString:enabled}
);
if (info.source == "feature-test") {
View logEvent listener.js
var impression_count = 0;
var count_impressions = function(logEvent){
var visitors = logEvent.params.visitors;
visitors.forEach(function(visitor){
console.log(visitor)
var snapshots = visitor.snapshots;
snapshots.forEach(function(snapshot){
var events = snapshot.events
events.forEach(function(event){
if(event.key == "campaign_activated"){
View segment_lambda.js
//const Integration = require('@segment/integration-sdk')
const optimizely = require('@optimizely/optimizely-sdk');
var defaultLogger = require('@optimizely/optimizely-sdk').logging;
var LOG_LEVEL = require('@optimizely/optimizely-sdk').enums.LOG_LEVEL;
var optimizelyClientInstance = optimizely.createInstance({
sdkKey: '15gywErrhRhKGHaTJCBw9Z',
logger: defaultLogger.createLogger({
logLevel: LOG_LEVEL.DEBUG
}) // Provide the sdkKey of your desired environment here
});
View akamai_cookie_creation_with_opt_check.json
@Danny-Driscoll
Danny-Driscoll / akamai_cookie_creation.json
Created Apr 3, 2019
Akamai Property Manager Rule configuration JSON for Optimizely cookie management
View akamai_cookie_creation.json
@Danny-Driscoll
Danny-Driscoll / New Yorker Headline Testing Prod 4-field Config
Last active Nov 29, 2018
4 fields Prod URL tageting headline testing
View New Yorker Headline Testing Prod 4-field Config
{
"experiment": {
"project_id": 2723621000,
"variations": [
{
"archived": false,
"key": "original",
"name": "Original",
"weight": 3333
},
@Danny-Driscoll
Danny-Driscoll / session_query.sql
Created Aug 7, 2017
Query introducing session definition based on session_id value
View session_query.sql
SELECT
experiment_id,
variation_id,
COUNT(DISTINCT end_user_id) AS unique_users,
COUNT(DISTINCT CASE WHEN is_converted = 1
THEN end_user_id END) AS unique_users_converted
FROM (
SELECT
sessions.end_user_id,
sessions.experiment_id,
@Danny-Driscoll
Danny-Driscoll / sample_indexed_unique_conversion_query.sql
Last active Aug 7, 2017
Sample query using a temporary index table to calculate unique conversions by variation for visitors first seen in a given time window
View sample_indexed_unique_conversion_query.sql
--Create a table indicating the first decision event for each user.
CREATE TABLE first_seen (userId varchar(64), first_seen DateTime);
CREATE INDEX first_seen_index ON first_seen (userId(64));
--Create index containing the relevant data.
CREATE INDEX pricing_index ON pricing (end_user_id(64), timestamp, event_name(100));
--Setup date parameters
SET @start_time = "2017-05-02 00:00:00";
SET @end_time = "2017-05-03 00:00:00";
View Outbrain Module Loading.js
window.jQuery(document).ajaxComplete(function(event, xhr, settings) {
if (settings && settings.url.indexOf('homepage3-zone-1') !== -1) {
console.log('Zone 3 back');
window.jQuery("#homepage3-zone-1 > div.l-container.zn__background--content-relative > div").before('<div class="OB_HOP_70"><div class="OUTBRAIN" data-src="http://www.cnn.com/" data-widget-id="HOP_70" data-ob-template="cnn" ></div></div>');
var pollForElement = function() {
if (window.OBR) {
window.OBR.extern.researchWidget();
}
else {
setTimeout(pollForElement, 50);