Skip to content

Instantly share code, notes, and snippets.

@Nils-van-Kleef
Nils-van-Kleef / segment_integration_for_crisp.js
Created May 15, 2020 18:40
Server-side only: Create users and track events in Crisp
// Learn more about destination functions API at
// https://segment.com/docs/connections/destinations/destination-functions
// Crisp API documentation: https://docs.crisp.chat/api/v1/
// !! Add your website_id here
const website_id = '9a2518c0-913f-46e6-acfe-3770cda57186';
var endpoint =
'https://api.crisp.chat/v1/website/' + website_id + '/people/profile';
@Nils-van-Kleef
Nils-van-Kleef / usabilla-optimizely-integration.json
Created November 27, 2017 18:52
Integration of Usabilla with Optimizely. Use in Custom Analytics Integrations
{
"plugin_type": "analytics_integration",
"name": "Usabilla",
"form_schema": [],
"description": "",
"options": {
"track_layer_decision": "console.log('4');\n\nfunction userCustomData() {\n ub_window = (document.getElementById('lightningjs-frame-usabilla_live') || {}).contentWindow || {};\n return (ub_window.usabilla_live_settings || {}).local_data\n}\n\nfunction updateUsbl() {\n \n\t// capture Optimizely data\n\tvar campaignInfo = optimizely.get('state').getDecisionObject({'campaignId': campaignId});\n\n\t//retrieve current Usabilla custom variables\n var usbllocaldata = userCustomData();\n var usblCustomVars = usbllocaldata.custom;\n\n //add Optimizely data to custom variable object\n usblCustomVars['Optimizely_' + campaignInfo.experiment] = campaignInfo.variation;\n\n //send updated custom variable object to Usabilla\n window.usabilla_live('data', {\n \t'custom': usblCustomVars\n });\n}\n\n//initiate polling for Usabilla object\n\nvar count = 0;\nvar poll = setInterval(function(){\n
@Nils-van-Kleef
Nils-van-Kleef / contentsquare-optimizely-integration.json
Created November 27, 2017 17:07
Integration of ContentSquare with Optimizely. Use in Custom Analytics Integrations
{
"plugin_type": "analytics_integration",
"name": "ContentSquare",
"form_schema": [
{
"default_value": "1",
"field_type": "dropdown",
"name": "customVar",
"label": "customVar",
"options": {
@Nils-van-Kleef
Nils-van-Kleef / OLD-amplitude-optimizely-integration.json
Last active May 8, 2018 13:25
[OLD] Integration of Amplitude with Optimizely. Use in Custom Analytics Integrations
{
"plugin_type": "analytics_integration",
"name": "Amplitude Analytics Integration",
"form_schema": [
{
"default_value": "[Optimizely] Experiment",
"field_type": "text",
"name": "property_prefix",
"label": "User Property Prefix",
"options": null
{
"plugin_type": "analytics_integration",
"name": "Amplitude Analytics Integration",
"form_schema": [
{
"default_value": "[Optimizely] Experiment",
"field_type": "text",
"name": "property_prefix",
"label": "User Property Prefix",
"options": null
@Nils-van-Kleef
Nils-van-Kleef / econda-optimizely-integration.js
Created November 27, 2017 15:59
Integration of Econda with Optimizely. Use in Custom Analytics Integrations (or Project JavaScript).
// Pre conditions :
// 1: Econda-Tracking-Script is loaded before
(function(){
var decObject = window.optimizely.get("state").getDecisionObject({campaignId: campaignId});
if( typeof window.emos3 !== 'undefined'){
window.emos3.send({ type: 'event', abtest: [ [decObject.experiment , decObject.variation] ] });
} else if (typeof(window.emosPropertiesEvent)== "function"){
window.emosPropertiesEvent({ type: 'event', abtest: [ [decObject.experiment , decObject.variation] ] });
} else {
console.log("Problem: econda A/B Test Tracking is activated but tracking library is not yet loaded. Could not send data to econda.");
@Nils-van-Kleef
Nils-van-Kleef / waitForOriginSync-optimizelyEndUserId-cookie.js
Created March 13, 2017 15:51
waitForOriginSync, but only if the optimizelyEndUserId cookie doesn't exist yet
@Nils-van-Kleef
Nils-van-Kleef / redirect-append-qp.js
Last active January 31, 2017 13:43
Redirect: adds query-parameter at the end
/* _optimizely_redirect=http://www.example.com */
var qp_addition = "newSearchWeb=true";
if (window.location.href.indexOf(qp_addition) < 0) {
var _optly = {redir: document.createElement("a")};
_optly.redir = {protocol: "https:" == document.location.protocol ? "https://" : "http://",
domain: window.location.hostname,
entire_url: window.location.href,
query: window.location.search
};
if (_optly.redir.query.length == 0) {
@Nils-van-Kleef
Nils-van-Kleef / redirect-to-https-www.js
Created December 16, 2016 14:50
Redirect: Strips href up to "www.", then Prepends https://www. and then executes redirect
/* _optimizely_redirect=http://www.example.com */
var toPrepend = "https://www.";
var hrefPostWWW = window.location.href.split("//")[1].replace("www.","");
var newHref = toPrepend.concat(hrefPostWWW);
window.location.replace(newHref);
@Nils-van-Kleef
Nils-van-Kleef / redirect-keep-substring.js
Last active September 7, 2016 11:20
Redirect - Keep string. This JavaScript will redirect a visitor to a different URL but keeps everything up until a defined part of the URL.
/* _optimizely_redirect=http://www.example.com */
var toKeep = "/[TO_KEEP]";
var addition = "/[NEW_ADDITION]";
var _optly = {redir: document.createElement("a")};
_optly.redir = {protocol: "https:" == document.location.protocol ? "https://" : "http://",
domain: window.location.hostname,
first: window.location.href.split(toKeep)[0],
query: window.location.search
};
_optly.redir.href = _optly.redir.first + toKeep + addition + _optly.redir.query;