-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat:Add config for omitting the batch timestamp #922
Changes from 4 commits
6b15343
9c3d2f9
e3a392d
cab72ad
0ec7822
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { MPID } from "@mparticle/web-sdk"; | ||
import { Dictionary } from "./utils"; | ||
import { IConsentRules } from "./consent"; | ||
|
||
export interface ICookieSyncManager { | ||
attemptCookieSync: (previousMPID: MPID, mpid: MPID, mpidIsNotInCookies: boolean) => void; | ||
performCookieSync: ( | ||
url: string, | ||
moduleId: number, | ||
mpid: MPID, | ||
cookieSyncDates: Dictionary<number>, | ||
filteringConsentRuleValues: IConsentRules, | ||
mpidIsNotInCookies: boolean, | ||
requiresConsent: boolean | ||
) => void; | ||
replaceAmpWithAmpersand: (string: string) => string; | ||
replaceMPID: (string: string, mpid: MPID) => string; | ||
|
||
/** | ||
* @deprecated replaceAmp has been deprecated, use replaceAmpersandWithAmp instead | ||
*/ | ||
replaceAmp: (string: string) => string; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,10 +56,25 @@ export function convertEvents( | |
currentConsentState = user.getConsentState(); | ||
} | ||
|
||
// determine what timestamp, if any, to use for the batch | ||
const { omitBatchTimestamp } = mpInstance._Store.SDKConfig; | ||
const { batchTimestampUnixtimeMsOverride } = mpInstance._Store; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just noticed that you're puling this from I think within There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Per your and my comments, I am striking out the above. |
||
|
||
let timestamp_unixtime_ms: number | null; | ||
|
||
if (batchTimestampUnixtimeMsOverride) { | ||
timestamp_unixtime_ms = batchTimestampUnixtimeMsOverride; | ||
} else if (omitBatchTimestamp) { | ||
timestamp_unixtime_ms = null; | ||
} else { | ||
timestamp_unixtime_ms = new Date().getTime(); | ||
} | ||
|
||
|
||
const upload: EventsApi.Batch = { | ||
source_request_id: mpInstance._Helpers.generateUniqueId(), | ||
mpid, | ||
timestamp_unixtime_ms: new Date().getTime(), | ||
timestamp_unixtime_ms, | ||
environment: lastEvent.Debug | ||
? EventsApi.BatchEnvironmentEnum.development | ||
: EventsApi.BatchEnvironmentEnum.production, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a utility function called
isNumber
that checks if the type isboolean
which is more suited for this kind of check.Just don't forget to import it from
/src/utils
😄There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, I think you suggestion is a good one—but I think it should be applied in
src/sdkToEventsApiConverter.ts
instead.In
src/apiClient.ts
, I think it's important that we allow the caller to "unset" a batch timestamp override. If we checkisNumber(options.batchTimestampUnixtimeMsOverride))
here, then the caller won't be able to remove the override and let the current timestamp (ornull
in the case ofomitBatchTimestamp
) to be used.So, I changed the flow slightly to
src/apiClient.ts
, allow a value ineventOptions
to be used to set thebatchTimestampUnixtimeMsOverride
in the store.src/sdkToEventsApiConverter.ts
, only ifisNumber(batchTimestampUnixtimeMsOverride)
will we apply the override.So setting
batchTimestampUnixtimeMsOverride: undefined
ineventOptions
will "clear" the override.What do you think?