部分公共组件配置化

This commit is contained in:
tangly1024.com
2023-11-08 19:05:35 +08:00
parent f96aa2242f
commit b2759c6d5e
34 changed files with 301 additions and 239 deletions

View File

@@ -4,42 +4,45 @@ import { useEffect } from 'react'
import BLOG from '@/blog.config'
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')
// 或者使用其他依赖数组,根据需要执行 handleAckee
useEffect(() => {
handleAckeeCallback()
}, [router])
// handleAckee 函数
const handleAckeeCallback = () => {
handleAckee(
router.asPath,
{
server: BLOG.ANALYTICS_ACKEE_DATA_SERVER,
domainId: BLOG.ANALYTICS_ACKEE_DOMAIN_ID
server: server,
domainId: domainId
},
{
/*
* Enable or disable tracking of personal data.
* We recommend to ask the user for permission before turning this option on.
*/
* Enable or disable tracking of personal data.
* We recommend to ask the user for permission before turning this option on.
*/
detailed: true,
/*
* Enable or disable tracking when on localhost.
*/
* Enable or disable tracking when on localhost.
*/
ignoreLocalhost: false,
/*
* Enable or disable the tracking of your own visits.
* This is enabled by default, but should be turned off when using a wildcard Access-Control-Allow-Origin header.
* Some browsers strictly block third-party cookies. The option won't have an impact when this is the case.
*/
* Enable or disable the tracking of your own visits.
* This is enabled by default, but should be turned off when using a wildcard Access-Control-Allow-Origin header.
* Some browsers strictly block third-party cookies. The option won't have an impact when this is the case.
*/
ignoreOwnVisits: false
}
)
}
// 或者使用其他依赖数组,根据需要执行 handleAckee
useEffect(() => {
handleAckeeCallback()
}, [router])
return null
}
@@ -53,8 +56,8 @@ export default Ackee
* @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 handleAckee = async function (pathname, environment, options = {}) {
await loadExternalResource(siteConfig('ANALYTICS_ACKEE_TRACKER'), 'js')
const ackeeTracker = window.ackeeTracker
const instance = ackeeTracker?.create(environment.server, options)