Skip to content

Instantly share code, notes, and snippets.

@Danny-Driscoll
Created August 9, 2019 17:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Danny-Driscoll/1dabd36f97b61625da2a28dc36fc6694 to your computer and use it in GitHub Desktop.
Save Danny-Driscoll/1dabd36f97b61625da2a28dc36fc6694 to your computer and use it in GitHub Desktop.
//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
});
exports.handler = async function (req, res) {
// Parse event and ensure we support
//const event = (await json(req))
console.log(req);
//var body = req.body;
console.log("Type is ",req.type);
console.log("Event is ", req.event);
console.log("AnonymousId is ", req.anonymousId);
console.log("User ID is ", req.userId);
if(req.type == 'track'){
console.log('type is track');
return optimizelyClientInstance.onReady().then(function(){
if(req.anonymousId){
optimizelyClientInstance.track(req.event,req.anonymousId);
}
if(req.userId != null){
optimizelyClientInstance.track(req.event,req.userId);
}
return new Promise(function(resolve){setTimeout(resolve,2000);});
});
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment