-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
co-authored-by: danilo neves cruz <[email protected]>
- Loading branch information
1 parent
5b88698
commit 695dbf3
Showing
7 changed files
with
59 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import type { Address } from "@exactly/common/validation"; | ||
import { Analytics } from "@segment/analytics-node"; | ||
import { captureException } from "@sentry/node"; | ||
|
||
if (!process.env.SEGMENT_WRITE_KEY) throw new Error("missing segment write key"); | ||
|
||
const analytics = new Analytics({ writeKey: process.env.SEGMENT_WRITE_KEY }); | ||
|
||
export function identify( | ||
user: Prettify<{ userId: Address } & Omit<Parameters<typeof analytics.identify>[0], "userId">>, | ||
) { | ||
analytics.identify(user); | ||
} | ||
|
||
export function track( | ||
action: Id< | ||
| { event: "CardIssued" } | ||
| { event: "CardFrozen" } | ||
| { event: "CardUnfrozen" } | ||
| { event: "TransactionAuthorized"; properties: { usdAmount: number } } | ||
>, | ||
) { | ||
analytics.track(action); | ||
} | ||
|
||
export function closeAndFlush() { | ||
return analytics.closeAndFlush(); | ||
} | ||
|
||
analytics.on("error", (error) => captureException(error, { level: "error" })); | ||
|
||
type Id<T> = Prettify<{ userId: Address } & T>; | ||
|
||
type Prettify<T> = { [K in keyof T]: T[K] } & unknown; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters