mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-24 07:26:50 +00:00
ACKEE
This commit is contained in:
@@ -1,29 +1,64 @@
|
||||
// import { useRouter } from 'next/router'
|
||||
'use strict'
|
||||
|
||||
import { useEffect } from 'react'
|
||||
import BLOG from '@/blog.config'
|
||||
import { loadExternalResource } from '@/lib/utils'
|
||||
import { useEffect } from 'react'
|
||||
import { useRouter } from 'next/router'
|
||||
|
||||
const Ackee = () => {
|
||||
const router = useRouter()
|
||||
useEffect(() => {
|
||||
loadExternalResource(BLOG.ANALYTICS_ACKEE_TRACKER, 'js').then(url => {
|
||||
const ackeeTracker = window.ackeeTracker
|
||||
console.log('ackeeTracker', ackeeTracker)
|
||||
})
|
||||
})
|
||||
handleAckee(
|
||||
router.asPath,
|
||||
{
|
||||
server: BLOG.ANALYTICS_ACKEE_DATA_SERVER,
|
||||
domainId: BLOG.ANALYTICS_ACKEE_DOMAIN_ID
|
||||
},
|
||||
{
|
||||
detailed: false,
|
||||
ignoreLocalhost: false
|
||||
}
|
||||
)
|
||||
}, [router])
|
||||
|
||||
// const router = useRouter()
|
||||
// useAckee(
|
||||
// router.asPath,
|
||||
// {
|
||||
// server: BLOG.ANALYTICS_ACKEE_DATA_SERVER,
|
||||
// domainId: BLOG.ANALYTICS_ACKEE_DOMAIN_ID
|
||||
// },
|
||||
// {
|
||||
// detailed: false,
|
||||
// ignoreLocalhost: true
|
||||
// }
|
||||
// )
|
||||
return null
|
||||
}
|
||||
|
||||
export default Ackee
|
||||
|
||||
/**
|
||||
* Function to use Ackee.
|
||||
* Creates an instance once and a new record every time the pathname changes.
|
||||
* Safely no-ops during server-side rendering.
|
||||
* @param {?String} pathname - Current path.
|
||||
* @param {Object} environment - Object containing the URL of the Ackee server and the domain id.
|
||||
* @param {?Object} options - Ackee options.
|
||||
*/
|
||||
const handleAckee = async function(pathname, environment, options = {}) {
|
||||
await loadExternalResource(BLOG.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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user