Merge pull request #3157 from DavidVentura/allowCreatedDate

Allow populating event's createdAt on the send endpoint
This commit is contained in:
Mike Cao 2025-03-01 15:22:56 -08:00 committed by GitHub
commit 0a5a79e046
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 5 deletions

View file

@ -122,14 +122,14 @@ export async function POST(request: Request) {
} }
// Visit info // Visit info
const now = Math.floor(new Date().getTime() / 1000); const createdAt = Math.floor((reqCreatedAt || new Date()).getTime() / 1000);
let visitId = cache?.visitId || uuid(sessionId, visitSalt()); let visitId = cache?.visitId || uuid(sessionId, visitSalt());
let iat = cache?.iat || now; let iat = cache?.iat || createdAt;
// Expire visit after 30 minutes // Expire visit after 30 minutes
if (now - iat > 1800) { if (createdAt - iat > 1800) {
visitId = uuid(sessionId, visitSalt()); visitId = uuid(sessionId, visitSalt());
iat = now; iat = createdAt;
} }
if (type === COLLECTION_TYPE.event) { if (type === COLLECTION_TYPE.event) {

View file

@ -83,6 +83,7 @@ async function relationalQuery(data: {
pageTitle: pageTitle?.substring(0, PAGE_TITLE_LENGTH), pageTitle: pageTitle?.substring(0, PAGE_TITLE_LENGTH),
eventType: eventName ? EVENT_TYPE.customEvent : EVENT_TYPE.pageView, eventType: eventName ? EVENT_TYPE.customEvent : EVENT_TYPE.pageView,
eventName: eventName ? eventName?.substring(0, EVENT_NAME_LENGTH) : null, eventName: eventName ? eventName?.substring(0, EVENT_NAME_LENGTH) : null,
createdAt,
tag, tag,
createdAt, createdAt,
}, },
@ -193,7 +194,7 @@ async function clickhouseQuery(data: {
urlPath: urlPath?.substring(0, URL_LENGTH), urlPath: urlPath?.substring(0, URL_LENGTH),
eventName: eventName?.substring(0, EVENT_NAME_LENGTH), eventName: eventName?.substring(0, EVENT_NAME_LENGTH),
eventData, eventData,
createdAt, createdAt: createdAtUTC,
}); });
} }