-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
10bb957
commit ecb3dc7
Showing
2 changed files
with
57 additions
and
20 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
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() |
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