-
-
Save agramonte/bd29dd78b306c9048dced7e5fda6bb83 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
let ip = event.headers["x-forwarded-for"]; | |
let getGeo = steps.trigger.event.query.getGeo; | |
let event_type = steps.trigger.event.query.event_type; | |
let api_key = steps.trigger.event.query.api_key; | |
var geo; | |
if (getGeo == "true") { | |
var geoip = require('geoip-lite'); | |
if (ip) { | |
geo = geoip.lookup(ip); | |
} | |
} | |
var amplitudeEvent = {}; | |
amplitudeEvent.event_type = event_type; | |
if (event_type == "app_launch") { | |
amplitudeEvent.session_id = Math.floor(new Date().getTime() / 1000); | |
} | |
if (steps.trigger.event.query.user_id) { | |
amplitudeEvent.user_id = steps.trigger.event.query.user_id; | |
} | |
if (steps.trigger.event.query.device_id) { | |
amplitudeEvent.device_id = steps.trigger.event.query.device_id; | |
} | |
if (steps.trigger.event.query.os_name) { | |
amplitudeEvent.os_name = steps.trigger.event.query.os_name; | |
} | |
if (steps.trigger.event.query.app_version) { | |
amplitudeEvent.app_version = steps.trigger.event.query.app_version; | |
} | |
if (steps.trigger.event.query.os_version) { | |
amplitudeEvent.os_version = steps.trigger.event.query.os_version; | |
} | |
if (steps.trigger.event.query.device_model) { | |
amplitudeEvent.device_model = steps.trigger.event.query.device_model; | |
} | |
if (geo) { | |
if (geo.country) { | |
amplitudeEvent.country = geo.country; | |
} | |
if (geo.region) { | |
amplitudeEvent.region = geo.region; | |
} | |
if (geo.city) { | |
amplitudeEvent.city = geo.city; | |
} | |
} | |
if (steps.trigger.event.query.language) { | |
amplitudeEvent.language = steps.trigger.event.query.language; | |
} | |
var payload = {}; | |
payload.api_key = api_key; | |
payload.events = []; | |
payload.events[0] = amplitudeEvent; | |
return payload; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment