Skip to content

Commit

Permalink
fix: mixpanel timestamp in ms (#2990)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gauravudia authored Jan 16, 2024
1 parent 6a959d4 commit 0da63a4
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 50 deletions.
7 changes: 4 additions & 3 deletions src/v0/destinations/mp/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const {
getTimeDifference,
getValuesAsArrayFromConfig,
removeUndefinedValues,
toUnixTimestamp,
toUnixTimestampInMS,
getFieldValueFromMessage,
checkInvalidRtTfEvents,
handleRtTfSingleEventError,
Expand Down Expand Up @@ -174,7 +174,8 @@ const getEventValueForTrackEvent = (message, destination) => {
if (mappedProperties.$insert_id) {
mappedProperties.$insert_id = mappedProperties.$insert_id.slice(-36);
}
const unixTimestamp = toUnixTimestamp(message.timestamp);

const unixTimestamp = toUnixTimestampInMS(message.timestamp || message.originalTimestamp);
let properties = {
...message.properties,
...get(message, 'context.traits'),
Expand Down Expand Up @@ -304,7 +305,7 @@ const processPageOrScreenEvents = (message, type, destination) => {
...mappedProperties,
token: destination.Config.token,
distinct_id: message.userId || message.anonymousId,
time: toUnixTimestamp(message.timestamp),
time: toUnixTimestampInMS(message.timestamp || message.originalTimestamp),
...buildUtmParams(message.context?.campaign),
};
if (destination.Config?.identityMergeApi === 'simplified') {
Expand Down
4 changes: 2 additions & 2 deletions src/v0/destinations/mp/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const {
extractCustomFields,
isAppleFamily,
getBrowserInfo,
toUnixTimestamp,
toUnixTimestampInMS,
batchMultiplexedEvents,
getSuccessRespEvents,
defaultBatchRequestConfig,
Expand Down Expand Up @@ -113,7 +113,7 @@ const createIdentifyResponse = (message, type, destination, responseBuilderSimpl
$token: token,
$distinct_id: message.userId || message.anonymousId,
$ip: get(message, 'context.ip') || message.request_ip,
$time: toUnixTimestamp(message.timestamp),
$time: toUnixTimestampInMS(message.timestamp || message.originalTimestamp),
};

if (destination?.Config.identityMergeApi === 'simplified') {
Expand Down
4 changes: 4 additions & 0 deletions src/v0/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1232,6 +1232,9 @@ function toUnixTimestamp(timestamp) {
return unixTimestamp;
}

// Accepts a timestamp and returns the corresponding unix timestamp in milliseconds
const toUnixTimestampInMS = (timestamp) => new Date(timestamp).getTime();

// Accecpts timestamp as a parameter and returns the difference of the same with current time.
function getTimeDifference(timestamp) {
const currentTime = Date.now();
Expand Down Expand Up @@ -2193,6 +2196,7 @@ module.exports = {
stripTrailingSlash,
toTitleCase,
toUnixTimestamp,
toUnixTimestampInMS,
updatePayload,
checkInvalidRtTfEvents,
simpleProcessRouterDest,
Expand Down
Loading

0 comments on commit 0da63a4

Please sign in to comment.