This commit is contained in:
Bill Yang 2025-03-14 16:45:05 -07:00
parent 071c65e5b4
commit c928e9ccbb
3 changed files with 47 additions and 13 deletions

View file

@ -56,11 +56,14 @@ class PageviewQueue {
// Process each pageview with its geo data
const processedPageviews = batch.map((pv) => {
const countryCode = geoData?.[pv.ipAddress]?.data?.countryIso || "";
const regionCode = geoData?.[pv.ipAddress]?.data?.subdivisions?.[0]?.isoCode || "";
const regionCode =
geoData?.[pv.ipAddress]?.data?.subdivisions?.[0]?.isoCode || "";
return {
site_id: pv.site_id,
timestamp: DateTime.fromISO(pv.timestamp).toFormat("yyyy-MM-dd HH:mm:ss"),
timestamp: DateTime.fromISO(pv.timestamp).toFormat(
"yyyy-MM-dd HH:mm:ss"
),
session_id: pv.sessionId,
user_id: pv.userId,
hostname: pv.hostname || "",
@ -77,8 +80,9 @@ class PageviewQueue {
screen_height: pv.screenHeight || 0,
device_type: getDeviceType(pv.screenWidth, pv.screenHeight, pv.ua),
country: countryCode,
iso_3166_2: countryCode && regionCode ? countryCode + "-" + regionCode : "",
}
iso_3166_2:
countryCode && regionCode ? countryCode + "-" + regionCode : "",
};
});
console.info("bulk insert: ", processedPageviews.length);