Skip to content

Commit

Permalink
fix: put amplitude back (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasrosario authored Aug 11, 2023
1 parent 10bb957 commit ecb3dc7
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 20 deletions.
75 changes: 55 additions & 20 deletions public/init_cca.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,60 @@
const initCCA = () => {
if (window.ClientAnalytics) {
const {init, PlatformName, logPageView} = window.ClientAnalytics;
init({
isProd: true,
amplitudeApiKey: 'dad8b0d591535ebbdced770c09367478',
platform: PlatformName.web,
projectName: 'OnchainSummer',
showDebugLogging: false,
version: '0.0.1',
apiEndpoint: 'https://cca-lite.coinbase.com'
});
if (window.ClientAnalytics) {
const { init, PlatformName, logPageView } = window.ClientAnalytics
init({
isProd: true,
amplitudeApiKey: 'dad8b0d591535ebbdced770c09367478',
platform: PlatformName.web,
projectName: 'OnchainSummer',
showDebugLogging: false,
version: '0.0.1',
apiEndpoint: 'https://cca-lite.coinbase.com',
})

function handleLocationChange() {
logPageView();
function getCookie(cname) {
let name = cname + '='
let decodedCookie = decodeURIComponent(document.cookie)
let ca = decodedCookie.split(';')
for (let i = 0; i < ca.length; i++) {
let c = ca[i]
while (c.charAt(0) === ' ') {
c = c.substring(1)
}
if (c.indexOf(name) === 0) {
return c.substring(name.length, c.length)
}
}
return ''
}
const TWENTY_YEARS_AS_MS = 630_720_000_000
const COOKIE_DEVICE_ID = 'onchainsummer_device_id'
function getDeviceId() {
let id = getCookie(COOKIE_DEVICE_ID)
if (!id) {
id = crypto.randomUUID()
const d = new Date()
d.setTime(d.getTime() + TWENTY_YEARS_AS_MS)
document.cookie =
COOKIE_DEVICE_ID +
'=' +
id +
';expires=' +
d.toUTCString() +
';path=/'
}
return id
}
identify({ deviceId: getDeviceId() })

// Attach the popstate event listener
window.addEventListener('popstate', handleLocationChange);

// capture first page
handleLocationChange();
function handleLocationChange() {
logPageView()
}
};
initCCA();

// Attach the popstate event listener
window.addEventListener('popstate', handleLocationChange)

// capture first page
handleLocationChange()
}
}
initCCA()
2 changes: 2 additions & 0 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ export default function RootLayout({
inter.variable
)}
>
<Script src="https://static-assets.coinbase.com/js/cca/v0.0.1.js" />
<Script src="/init_cca.js" />
<QueryClientProvider>
<QueryParamProvider>
<Providers>
Expand Down

0 comments on commit ecb3dc7

Please sign in to comment.