Retrieves Geo location from the header ip.
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 event_type = steps.trigger.event.query.event_type; | |
let api_key = steps.trigger.event.query.api_key; | |
var geo; | |
var geoip = require('geoip-lite'); | |
if (ip) { | |
geo = geoip.lookup(ip); | |
} | |
var amplitudeEvent = {}; | |
amplitudeEvent.event_type = event_type; | |
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