Skip to content

Commit

Permalink
UPDATE: event clause logic for geo data
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremiahUy committed Nov 4, 2022
1 parent 5ff4851 commit c102e0e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/filters/add-geo-data.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const geoLookup = require('geoip-lite').lookup;
module.exports = function(inputEvents, ip) {
const outputEvents = [];
const geoData = geoLookup(ip);
if(ip){
const geoData = geoLookup(ip);
inputEvents.forEach(event => {
const cloneEvent = Object.assign({}, event);
cloneEvent.user_agent = null;
Expand All @@ -15,7 +15,6 @@ module.exports = function(inputEvents, ip) {
outputEvents.push(cloneEvent);
});
} else {
const geoData = geoLookup(ip);
inputEvents.forEach(event => {
const cloneEvent = Object.assign({}, event);
cloneEvent.user_agent = null;
Expand Down
4 changes: 3 additions & 1 deletion src/routes/collect-auto.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ const customHandler = function (request, reply, ingresses) {

} else {
const eventsWithProxyData = addProxyData(eventsWithClusterData, process.env.NAIS_APP_IMAGE);
let eventsWithGeoData = addGeoData(eventsWithProxyData, request.ip);
let eventsWithGeoData;
if(request.api_properties && request.api_properties.ip_address) {
eventsWithGeoData = addGeoData(eventsWithProxyData, undefined);
} else {
eventsWithGeoData = addGeoData(eventsWithProxyData, request.ip);
}
const eventsWithUrlsCleaned = cleanEventUrls(eventsWithGeoData);

Expand Down
4 changes: 3 additions & 1 deletion src/routes/collect.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ const handler = function(request, reply) {
reply.send(constants.IGNORED);
} else {
const eventsWithProxyData = addProxyData(inputEvents, process.env.NAIS_APP_IMAGE);
let eventsWithGeoData = addGeoData(eventsWithProxyData, request.ip);
let eventsWithGeoData;
if(request.api_properties && !request.api_properties.ip_address) {
eventsWithGeoData = addGeoData(eventsWithProxyData, undefined);
} else {
eventsWithGeoData = addGeoData(eventsWithProxyData, request.ip);
}
const eventsWithUrlsCleaned = cleanEventUrls(eventsWithGeoData);
forwardEvents(eventsWithUrlsCleaned, apiKey, process.env.AMPLITUDE_URL).then(function(response) {
Expand Down

0 comments on commit c102e0e

Please sign in to comment.