-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1098 from crowdbotics/qa
Release QA to Production
- Loading branch information
Showing
13 changed files
with
198 additions
and
65 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
export const PRODUCTION_AMPLITUDE_KEY = "b48a6aaef8d0ac8df1f2a78196473f06"; | ||
export const DEVELOPMENT_AMPLITUDE_KEY = "8fa9ae919aaf5bbfb85f8275b734b11c"; | ||
|
||
export const CUSTOMER_TYPE = { | ||
SMB: "SMB", | ||
ENT: "ENT" | ||
}; |
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,71 @@ | ||
import { configFile } from "../utils/configFile.js"; | ||
import { AMPLITUDE_API_KEY, OPT_IN_NAME } from "./config.js"; | ||
import { init, track, Identify, identify } from "@amplitude/analytics-node"; | ||
import { currentUser } from "../utils/user.js"; | ||
|
||
class AmplitudeWrapper { | ||
get userType() { | ||
// TODO: Implement once we have the data available in the UserSerializer | ||
return undefined; | ||
} | ||
|
||
get optedIn() { | ||
return configFile.get(OPT_IN_NAME); | ||
} | ||
|
||
get appProps() { | ||
return {}; | ||
} | ||
|
||
get userProps() { | ||
const org = currentUser.get("organization"); | ||
return { | ||
"User Type": this.userType, | ||
"Org ID": org?.id, | ||
Source: "CLI" | ||
}; | ||
} | ||
|
||
async init({ token = AMPLITUDE_API_KEY, options = {} } = {}) { | ||
if (!this.optedIn || !token) return; | ||
|
||
try { | ||
await init(token, { ...options, includeUtm: true }).promise; | ||
} catch { | ||
// Ignore errors during initialization | ||
} | ||
} | ||
|
||
async loadAndIdentify(user) { | ||
await currentUser.setUser(user); | ||
if (!currentUser.get("email")) return; | ||
|
||
const identifyEvent = new Identify(); | ||
identifyEvent.set("Django Id", currentUser.get("id")); | ||
identify(identifyEvent, { user_id: currentUser.get("email") }); | ||
} | ||
|
||
async sendEvent({ name, properties = {}, user }) { | ||
if (!this.optedIn) return; | ||
|
||
try { | ||
await this.init(); | ||
await this.loadAndIdentify(user); | ||
|
||
const userEmail = currentUser.get("email"); | ||
if (userEmail) { | ||
const updatedProps = { | ||
...properties, | ||
...this.appProps, | ||
...this.userProps | ||
}; | ||
|
||
await track(name, updatedProps, { user_id: userEmail }).promise; | ||
} | ||
} catch (error) { | ||
console.warn("Error handling analytics - skipping"); | ||
} | ||
} | ||
} | ||
|
||
export const Amplitude = new AmplitudeWrapper(); |
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
Oops, something went wrong.