question #2
I am trying to use a transformation to add geoenrichement to events ... this is my transformation, but I am not seeing geo info added to fb or bigquery...
what am i doing wrong?
/***
* This transformation enables customers to extract URL parameters. This
* enables the data to be processed for specific destinations as well as add geo enrichment
***/
export async function transformEvent(event, metadata) {
// Extract URL parameters
const search = event.context?.page?.search;
if (search) {
event.context.page.parameters = {};
search.substring(1).split("&").forEach(parameter => {
const [key, value] = parameter.split("=");
event.context.page.parameters[key] = decodeURIComponent(value);
});
}
// Enrich with geolocation data
if (event.request_ip) {
try {
const apiKey = "KEY"; // Replace with your actual API key
const url = `
https://api.ipgeolocation.io/ipgeo?apiKey=${apiKey}&ip=${event.request_ip}`;
const response = await fetch(url);
const geolocationData = await response.json();
if (response.ok) {
event.context.geolocation = geolocationData;
} else {
// Handle error (e.g., log or set a default geolocation)
}
} catch (error) {
// Handle fetch error (e.g., log the error)
}
}
return event;
}