Skip to content

Commit

Permalink
chore: add stats for shopify anonId resolution based on shopifyTopic …
Browse files Browse the repository at this point in the history
…and method
  • Loading branch information
anantjain45823 committed Dec 7, 2023
1 parent e1714bd commit 35100ba
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/util/prometheus.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,12 @@ class Prometheus {
type: 'counter',
labelNames: ['type', 'writeKey', 'source'],
},
{
name: 'shopify_anon_id_resolve',
help: 'shopify_anon_id_resolve',
type: 'counter',
labelNames: ['method', 'writeKey', 'shopifyTopic'],
},
{
name: 'shopify_redis_calls',
help: 'shopify_redis_calls',
Expand Down
2 changes: 1 addition & 1 deletion src/v0/sources/shopify/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ const processEvent = async (inputEvent, metricMetadata) => {
if (message.type !== EventType.IDENTIFY) {
const { anonymousId, sessionId } = await getAnonymousIdAndSessionId(
message,
metricMetadata,
{ shopifyTopic, ...metricMetadata },
redisData,
);
if (isDefinedAndNotNull(anonymousId)) {
Expand Down
11 changes: 11 additions & 0 deletions src/v0/sources/shopify/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ const getAnonymousIdAndSessionId = async (message, metricMetadata, redisData = n
}
// falling back to cartToken mapping or its hash in case no rudderAnonymousId or rudderSessionId is found
if (isDefinedAndNotNull(anonymousId) && isDefinedAndNotNull(sessionId)) {
stats.increment('shopify_anon_id_resolve', {
method: 'note_attributes',
...metricMetadata,
});
return { anonymousId, sessionId };
}
const cartToken = getCartToken(message);
Expand All @@ -189,6 +193,13 @@ const getAnonymousIdAndSessionId = async (message, metricMetadata, redisData = n
Hash the id and use it as anonymousId (limiting 256 -> 36 chars) and sessionId is not sent as its not required field
*/
anonymousId = v5(cartToken, v5.URL);
} else {
// This metric let us know how many events based on event name used redis for anonId resolution
// and for how many
stats.increment('shopify_anon_id_resolve', {
method: 'database',
...metricMetadata,
});
}
return { anonymousId, sessionId };
};
Expand Down

0 comments on commit 35100ba

Please sign in to comment.