-
Notifications
You must be signed in to change notification settings - Fork 367
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Client Analytics Pageview Tracking (#29)
* Add Client Analytics pageview tracking to Base Docs app. * Add Client Analytics pageview tracking to Base Web app. * Add import plugin to fix dotenv linting in docusaurus.config.js * Switch to .ts files and disable type-checking and linting. * Update initCCA file extension in docs config. * Add execution environment check before using window variable. * Replace process.env with publicRuntimeConfig. * Remove Amplitude env vars. Remove device id from analytics init files. * Remove duplicate dotenv call.
- Loading branch information
1 parent
9fea28a
commit 571ec39
Showing
9 changed files
with
126 additions
and
13 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,48 @@ | ||
// The CCA team said this lite version of the library is temporary and not officially supported. | ||
// They recommended disabling linting and type-checking for now, since this version is not typed. | ||
/* eslint-disable */ | ||
// @ts-nocheck | ||
const docusaurusConfig = require('@generated/docusaurus.config'); | ||
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment'; | ||
|
||
const { customFields } = docusaurusConfig.default; | ||
const isDevelopment = customFields.nodeEnv === 'development'; | ||
|
||
// Initialize Client Analytics | ||
const initCCA = () => { | ||
if (ExecutionEnvironment.canUseDOM && window.ClientAnalytics) { | ||
const { init, identify, PlatformName } = window.ClientAnalytics; | ||
|
||
init({ | ||
isProd: !isDevelopment, | ||
amplitudeApiKey: isDevelopment | ||
? 'ca92bbcb548f7ec4b8ebe9194b8eda81' | ||
: '2b38c7ac93c0dccc83ebf9acc5107413', | ||
platform: PlatformName.web, | ||
projectName: 'base_docs', | ||
showDebugLogging: isDevelopment, | ||
version: '1.0.0', | ||
apiEndpoint: 'https://cca-lite.coinbase.com', | ||
}); | ||
|
||
identify({ deviceId: 'base_docs_device_id' }); | ||
} | ||
}; | ||
|
||
export default initCCA(); | ||
|
||
// Track Pageviews | ||
export function onRouteDidUpdate({ location, previousLocation }) { | ||
if (location.pathname !== previousLocation?.pathname && window.ClientAnalytics) { | ||
const { logEvent } = window.ClientAnalytics; | ||
|
||
const referrerURL = | ||
previousLocation?.pathname === null && document.referrer ? document.referrer : null; | ||
|
||
logEvent('pageview', { | ||
page_path: location.pathname, | ||
prev_page_path: previousLocation?.pathname, | ||
referrer_url: referrerURL, | ||
}); | ||
} | ||
} |
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,35 @@ | ||
// The CCA team said this lite version of the library is temporary and not officially supported. | ||
// They recommended disabling linting and type-checking for now, since this version is not typed. | ||
/* eslint-disable */ | ||
// @ts-nocheck | ||
import getConfig from 'next/config'; | ||
|
||
const { publicRuntimeConfig } = getConfig(); | ||
const isDevelopment = publicRuntimeConfig.nodeEnv === 'development'; | ||
|
||
// CCA library loads in _app.tsx | ||
const initCCA = (router) => { | ||
if (window.ClientAnalytics) { | ||
const { init, identify, PlatformName, initNextJsTrackPageview } = window.ClientAnalytics; | ||
|
||
init({ | ||
isProd: !isDevelopment, | ||
amplitudeApiKey: isDevelopment | ||
? 'ca92bbcb548f7ec4b8ebe9194b8eda81' | ||
: '2b38c7ac93c0dccc83ebf9acc5107413', | ||
platform: PlatformName.web, | ||
projectName: 'base_web', | ||
showDebugLogging: isDevelopment, | ||
version: '1.0.0', | ||
apiEndpoint: 'https://cca-lite.coinbase.com', | ||
}); | ||
|
||
identify({ deviceId: 'base_web_device_id' }); | ||
|
||
initNextJsTrackPageview({ | ||
nextJsRouter: router, | ||
}); | ||
} | ||
}; | ||
|
||
export default initCCA; |
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