Skip to content

Instantly share code, notes, and snippets.

View robisatthefunction's full-sized avatar

Robert Saunders robisatthefunction

  • Optimizely
View GitHub Profile
window.optimizelyEdge = window.optimizelyEdge || [];
window.optimizelyEdge.push({
type: 'addListener',
filter: {
type: 'lifecycle',
name: 'campaignDecided'
},
handler: (event) => {
var campaignId = event.data.decision.campaignId;
import boto3
# Get AWS credentials from your Optimizely Interface https://docs.developers.optimizely.com/web/docs/customer-profiles#bulk-upload
client = boto3.client(
's3',
aws_access_key_id = '',
aws_secret_access_key = ''
)
# https://docs.aws.amazon.com/AmazonS3/latest/userguide/access-bucket-intro.html
const onDecision = ({ type, userId, attributes, decisionInfo }) => {
// Check if a decision event was dispatched
if (decisionInfo['decisionEventDispatched']) {
// Get experiment bucketing info
const experimentKey = decisionInfo['ruleKey']
const variationKey = decisionInfo['variationKey']
const decisionString = '('+experimentKey+'):('+variationKey+')';
// Sends decision info through eVar2
const onDecision = ({ type, userId, attributes, decisionInfo }) => {
// Check if a decision event was dispatched
if (decisionInfo['decisionEventDispatched']) {
// Get experiment bucketing info
const experimentKey = decisionInfo['ruleKey']
const variationKey = decisionInfo['variationKey']
// Optionally send a track event to Optimizely to record integration success. Make sure to have an Optimizely client or withOptimizely client instantiated
optimizely.track('segment_success');
function getCookie(name){
var match = document.cookie.match(name + '=([^;]*)');
return match ? match[1] : undefined;
}
var optId = getCookie('nameOfCookie');
import React, { useState, useEffect } from "react";
var optlyPages = window.optimizelyEdge.get("state").getActivePages();
// Implement the following method
function activateOptlyPage(optlyPage) {
var _apiName = optlyPage.apiName;
//Force deactivation of the page
window.optimizelyEdge.push({
{
"plugin_type": "analytics_integration",
"name": "Custom GA Integration Using Custom Dimensions",
"form_schema": [
{
"default_value": "",
"field_type": "text",
"name": "customTracker",
"label": "Custom Tracker",
"options": null
// This code would go in a script above the Optimizely snippet! You will need to replace the cookie names with the names of your compliance cookies, they are just placeholders for the general logic that can be used.
// https://support.optimizely.com/hc/en-us/articles/4410284332685-Project-Settings-jQuery-and-Project-JavaScript-settings-in-Optimizely
// Declare function necessary to get cookies by name
function getCookie(cookieName) {
let cookie = {};
document.cookie.split(';').forEach(function(el) {
let [key,value] = el.split('=');
cookie[key.trim()] = value;
});
// setCookie('name of cookie', 'value', # days till expire, 'your site domain')
var setCookie = function(c_name,value,exdays,c_domain) {
c_domain = (typeof c_domain === "undefined") ? "" : "domain=" + c_domain + ";";
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value + ";" + c_domain + "path=/";
};