-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Track collection events (#2256)
- Renames `inject_analytics` to `inject_extra` and updates docs - Manually tracks page views to enable passing custom props - Tracks copying collection share link and downloading a public collection --------- Co-authored-by: emma <[email protected]>
- Loading branch information
Showing
13 changed files
with
149 additions
and
30 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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* Global constants to make available to build | ||
* | ||
* @TODO Consolidate webpack and web-test-runner esbuild configs | ||
*/ | ||
const path = require("path"); | ||
|
||
const isDevServer = process.env.WEBPACK_SERVE; | ||
|
||
const dotEnvPath = path.resolve( | ||
process.cwd(), | ||
`.env${isDevServer ? `.local` : ""}`, | ||
); | ||
require("dotenv").config({ | ||
path: dotEnvPath, | ||
}); | ||
|
||
const WEBSOCKET_HOST = | ||
isDevServer && process.env.API_BASE_URL | ||
? new URL(process.env.API_BASE_URL).host | ||
: process.env.WEBSOCKET_HOST || ""; | ||
|
||
module.exports = { | ||
"window.process.env.WEBSOCKET_HOST": JSON.stringify(WEBSOCKET_HOST), | ||
"window.process.env.ANALYTICS_NAMESPACE": JSON.stringify( | ||
process.env.ANALYTICS_NAMESPACE || "", | ||
), | ||
}; |
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,9 @@ | ||
/** | ||
* All available analytics tracking events | ||
*/ | ||
|
||
export enum AnalyticsTrackEvent { | ||
PageView = "pageview", | ||
CopyShareCollectionLink = "Copy share collection link", | ||
DownloadPublicCollection = "Download public collection", | ||
} |
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,40 @@ | ||
/** | ||
* Custom tracking for analytics. | ||
* | ||
* Any third-party analytics script will need to have been made | ||
* available through the `extra.js` injected by the server. | ||
*/ | ||
|
||
import { AnalyticsTrackEvent } from "../trackEvents"; | ||
|
||
export type AnalyticsTrackProps = { | ||
org_slug: string | null; | ||
collection_id?: string | null; | ||
collection_name?: string | null; | ||
logged_in?: boolean; | ||
}; | ||
|
||
export function track( | ||
event: `${AnalyticsTrackEvent}`, | ||
props?: AnalyticsTrackProps, | ||
) { | ||
// ANALYTICS_NAMESPACE is specified with webpack `DefinePlugin` | ||
const analytics = window.process.env.ANALYTICS_NAMESPACE | ||
? // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
(window as any)[window.process.env.ANALYTICS_NAMESPACE] | ||
: null; | ||
|
||
if (!analytics) { | ||
return; | ||
} | ||
|
||
try { | ||
analytics(event, { props }); | ||
} catch (err) { | ||
console.debug(err); | ||
} | ||
} | ||
|
||
export function pageView(props?: AnalyticsTrackProps) { | ||
track(AnalyticsTrackEvent.PageView, props); | ||
} |
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