Skip to content

Commit

Permalink
Added analytics event fully after ctx.waitUntil
Browse files Browse the repository at this point in the history
  • Loading branch information
Cosmin-Parvulescu committed Sep 21, 2023
1 parent ebd995a commit 3a65461
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
26 changes: 14 additions & 12 deletions platform/starbase/src/jsonrpc/methods/publishApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,19 @@ export const publishApp = async ({

await appDO.class.publish(input.published)

const { edges: ownershipEdges } = await caller.edges.getEdges({
query: {
tag: EDGE_APPLICATION,
dst: { baseUrn: appURN },
},
})
if (ownershipEdges.length === 0) {
throw new InternalServerError({
message: 'App ownership edge not found',
const buildAnalyticsEvent = async () => {
const { edges: ownershipEdges } = await caller.edges.getEdges({
query: {
tag: EDGE_APPLICATION,
dst: { baseUrn: appURN },
},
})
}
if (ownershipEdges.length === 0) {
throw new InternalServerError({
message: 'App ownership edge not found',
})
}

ctx.waitUntil?.(
createAnalyticsEvent({
distinctId: ctx.identityURN as IdentityURN,
eventName: input.published
Expand All @@ -89,7 +89,9 @@ export const publishApp = async ({
},
},
})
)
}

ctx.waitUntil?.(buildAnalyticsEvent())

return {
published: true,
Expand Down
26 changes: 14 additions & 12 deletions platform/starbase/src/jsonrpc/methods/setAppPlan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,19 @@ export const setAppPlan = async ({
})
)

const { edges: ownershipEdges } = await caller.edges.getEdges({
query: {
tag: EDGE_APPLICATION,
dst: { baseUrn: appURN },
},
})
if (ownershipEdges.length === 0) {
throw new InternalServerError({
message: 'App ownership edge not found',
const buildAnalyticsEvent = async () => {
const { edges: ownershipEdges } = await caller.edges.getEdges({
query: {
tag: EDGE_APPLICATION,
dst: { baseUrn: appURN },
},
})
}
if (ownershipEdges.length === 0) {
throw new InternalServerError({
message: 'App ownership edge not found',
})
}

ctx.waitUntil?.(
createAnalyticsEvent({
eventName: `app_set_${plan}_plan`,
apiKey: ctx.POSTHOG_API_KEY,
Expand All @@ -108,5 +108,7 @@ export const setAppPlan = async ({
},
},
})
)
}

ctx.waitUntil?.(buildAnalyticsEvent())
}

0 comments on commit 3a65461

Please sign in to comment.