Skip to content
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

migrate segment to HT #6

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions core/analytics.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os from 'os';
import { Analytics as Segment } from '@segment/analytics-node';
import { HtEvents } from '@ht-sdks/events-sdk-js-node';
import { loadConfig } from './config';
import { addShutdownTask } from './utils/shutdown';

Expand All @@ -9,11 +9,14 @@ export interface Analytics {
prepareForShutdown(): Promise<void>;
}

export class SegmentAnalytics implements Analytics {
private segment: Segment;
export class HightouchAnalytics implements Analytics {
private htevents: HtEvents;

constructor() {
this.segment = new Segment({ writeKey: 'g9GIEwAL2HOQHq6PXg9gHzSjEBuAuRLq' });
this.htevents = new HtEvents({
writeKey: 'beb757ad12ccfdaa3d8a1ada480ead6719b7d9033a747bc55b66cc4c18d18347',
host: 'https://us-east-1.hightouch-events.com',
});
addShutdownTask(async (reason) => {
this.logEvent('cli-tool-shutdown', reason);
await this.prepareForShutdown();
Expand All @@ -23,20 +26,20 @@ export class SegmentAnalytics implements Analytics {
logEvent(event: string, data: any): void {
const config = loadConfig();
if (config?.shouldTrackUsageData ?? false) {
this.segment.track({ anonymousId: config?.id ?? '', event, properties: data });
this.htevents.track({ anonymousId: config?.id ?? '', event, properties: data });
}
}

identifyUser(userId: string) {
const config = loadConfig();
if (config?.shouldTrackUsageData ?? false) {
this.segment.identify({ userId, traits: { os: os.platform } });
this.htevents.identify({ userId, traits: { os: os.platform } });
}
}

async prepareForShutdown(): Promise<void> {
await this.segment.closeAndFlush();
await this.htevents.closeAndFlush();
}
}

export const SharedAnalytics = new SegmentAnalytics();
export const SharedAnalytics = new HightouchAnalytics();
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
]
},
"dependencies": {
"@segment/analytics-node": "^1.1.0",
"@ht-sdks/events-sdk-js-node": "^1.0.0",
"binaryextensions": "^4.18.0",
"ejs": "^3.1.10",
"enquirer": "^2.4.1",
Expand Down
40 changes: 20 additions & 20 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,26 @@
resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.57.0.tgz#a5417ae8427873f1dd08b70b3574b453e67b5f7f"
integrity sha512-Ys+3g2TaW7gADOJzPt83SJtCDhMjndcDMFVQ/Tj9iA1BfJzFKD9mAUXT3OenpuPHbI6P/myECxRJrofUsDx/5g==

"@ht-sdks/events-sdk-js-core@^1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@ht-sdks/events-sdk-js-core/-/events-sdk-js-core-1.1.0.tgz#15f68893614f380d6ec7c2b17c84504c74e8b522"
integrity sha512-x8xNf9KueBOhs1yYJ6DkoUdHizQsTc0R6sMwX02CCrkIxM3H6/ySTafz0n9JpNbCFBQFEKxe9UwWfB2WwbDXPA==
dependencies:
"@lukeed/uuid" "^2.0.0"
dset "^3.1.2"
tslib "^2.4.1"

"@ht-sdks/events-sdk-js-node@^1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@ht-sdks/events-sdk-js-node/-/events-sdk-js-node-1.0.0.tgz#7ead1190263c2f50a8127551a4cc24387846ee5e"
integrity sha512-CmdT5NDa4s87RK9jzpqW+shxP1G4lUn8OuJLysE5Rg31rQHBMI+KnAF+Zk+QMD8Kk+ScZBgdVuWOA35HgCLU+g==
dependencies:
"@ht-sdks/events-sdk-js-core" "^1.1.0"
"@lukeed/uuid" "^2.0.0"
buffer "^6.0.3"
node-fetch "^2.6.7"
tslib "^2.4.1"

"@humanwhocodes/config-array@^0.11.14":
version "0.11.14"
resolved "https://registry.yarnpkg.com/@humanwhocodes/config-array/-/config-array-0.11.14.tgz#d78e481a039f7566ecc9660b4ea7fe6b1fec442b"
Expand Down Expand Up @@ -438,26 +458,6 @@
resolved "https://registry.yarnpkg.com/@rushstack/eslint-patch/-/eslint-patch-1.10.4.tgz#427d5549943a9c6fce808e39ea64dbe60d4047f1"
integrity sha512-WJgX9nzTqknM393q1QJDJmoW28kUfEnybeTfVNcNAPnIx210RXm2DiXiHzfNPJNIUUb1tJnz/l4QGtJ30PgWmA==

"@segment/[email protected]":
version "1.3.0"
resolved "https://registry.npmjs.org/@segment/analytics-core/-/analytics-core-1.3.0.tgz"
integrity sha512-ujScWZH49NK1hYlp2/EMw45nOPEh+pmTydAnR6gSkRNucZD4fuinvpPL03rmFCw8ibaMuKLAdgPJfQ0gkLKZ5A==
dependencies:
"@lukeed/uuid" "^2.0.0"
dset "^3.1.2"
tslib "^2.4.1"

"@segment/analytics-node@^1.1.0":
version "1.1.0"
resolved "https://registry.npmjs.org/@segment/analytics-node/-/analytics-node-1.1.0.tgz"
integrity sha512-q8MPpvQJgMUSIRmQXficA33ZmLQ6s5YqUMr623xJhhfp/TGkkgfpcdMk+qSniZVIm8JuQRXm8Mbh922LG3goBQ==
dependencies:
"@lukeed/uuid" "^2.0.0"
"@segment/analytics-core" "1.3.0"
buffer "^6.0.3"
node-fetch "^2.6.7"
tslib "^2.4.1"

"@sindresorhus/is@^4.0.0":
version "4.6.0"
resolved "https://registry.npmjs.org/@sindresorhus/is/-/is-4.6.0.tgz"
Expand Down
Loading