Created
August 9, 2019 17:16
-
-
Save Danny-Driscoll/1dabd36f97b61625da2a28dc36fc6694 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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