|
'use strict' |
|
|
|
import { useEffect } from 'react' |
|
import { loadExternalResource } from '@/lib/utils' |
|
import { useRouter } from 'next/router' |
|
import { siteConfig } from '@/lib/config' |
|
const Ackee = () => { |
|
const router = useRouter() |
|
const server = siteConfig('ANALYTICS_ACKEE_DATA_SERVER') |
|
const domainId = siteConfig('ANALYTICS_ACKEE_DOMAIN_ID') |
|
|
|
|
|
useEffect(() => { |
|
handleAckeeCallback() |
|
}, [router]) |
|
|
|
|
|
const handleAckeeCallback = () => { |
|
handleAckee( |
|
router.asPath, |
|
{ |
|
server: server, |
|
domainId: domainId |
|
}, |
|
{ |
|
|
|
|
|
|
|
|
|
detailed: true, |
|
|
|
|
|
|
|
ignoreLocalhost: false, |
|
|
|
|
|
|
|
|
|
|
|
ignoreOwnVisits: false |
|
} |
|
) |
|
} |
|
|
|
return null |
|
} |
|
|
|
export default Ackee |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const handleAckee = async function (pathname, environment, options = {}) { |
|
await loadExternalResource(siteConfig('ANALYTICS_ACKEE_TRACKER'), 'js') |
|
const ackeeTracker = window.ackeeTracker |
|
|
|
const instance = ackeeTracker?.create(environment.server, options) |
|
|
|
if (instance == null) { |
|
console.warn('Skipped record creation because useAckee has been called in a non-browser environment') |
|
return |
|
} |
|
|
|
const hasPathname = ( |
|
pathname != null && pathname !== '' |
|
) |
|
|
|
if (hasPathname === false) { |
|
console.warn('Skipped record creation because useAckee has been called without pathname') |
|
return |
|
} |
|
|
|
const attributes = ackeeTracker?.attributes(options.detailed) |
|
const url = new URL(pathname, location) |
|
|
|
return instance.record(environment.domainId, { |
|
...attributes, |
|
siteLocation: url.href |
|
}).stop |
|
} |
|
|