2025-01-29 20:28:22 +00:00
|
|
|
import { defineNuxtModule, addPlugin, addImportsDir, createResolver, useLogger } from '@nuxt/kit'
|
2023-09-13 14:19:43 +00:00
|
|
|
import { defu } from 'defu'
|
2023-05-14 15:25:44 +00:00
|
|
|
|
2023-05-18 12:33:46 +00:00
|
|
|
const logger = useLogger('nuxt:wideangle')
|
|
|
|
|
|
|
|
export interface ModuleOptions {
|
|
|
|
siteId?: string
|
2023-09-13 14:19:43 +00:00
|
|
|
domain: string
|
|
|
|
fingerprint: boolean
|
2025-01-29 20:28:22 +00:00
|
|
|
suppressDnt: boolean
|
2023-09-13 14:19:43 +00:00
|
|
|
includeParams: string[]
|
|
|
|
excludePaths: string[]
|
|
|
|
ignoreHash: boolean
|
2025-01-29 20:28:22 +00:00
|
|
|
consentMarker: string
|
2023-05-18 12:33:46 +00:00
|
|
|
}
|
2023-05-14 15:25:44 +00:00
|
|
|
|
|
|
|
export default defineNuxtModule<ModuleOptions>({
|
|
|
|
meta: {
|
|
|
|
name: 'wideangle',
|
2023-05-18 12:33:46 +00:00
|
|
|
configKey: 'wideangle',
|
|
|
|
compatibility: {
|
2025-01-29 20:28:22 +00:00
|
|
|
nuxt: '>=3',
|
|
|
|
},
|
2023-05-18 12:33:46 +00:00
|
|
|
},
|
|
|
|
defaults: {
|
2025-01-29 20:28:22 +00:00
|
|
|
domain: 'stats.wideangle.co',
|
2023-05-18 12:33:46 +00:00
|
|
|
fingerprint: false,
|
2025-01-29 20:28:22 +00:00
|
|
|
suppressDnt: false,
|
2023-05-18 12:33:46 +00:00
|
|
|
includeParams: [],
|
|
|
|
excludePaths: [],
|
2025-01-29 20:28:22 +00:00
|
|
|
ignoreHash: false,
|
|
|
|
consentMarker: undefined,
|
2023-05-14 15:25:44 +00:00
|
|
|
},
|
2025-01-29 20:28:22 +00:00
|
|
|
setup(options, nuxt) {
|
|
|
|
const resolver = createResolver(import.meta.url)
|
2023-09-13 14:19:43 +00:00
|
|
|
nuxt.options.runtimeConfig.public.wideangle = defu(
|
|
|
|
nuxt.options.runtimeConfig.public.wideangle,
|
|
|
|
options,
|
|
|
|
)
|
|
|
|
|
2025-01-29 20:28:22 +00:00
|
|
|
nuxt.options.build.transpile.push(resolver.resolve('./runtime'))
|
2023-09-13 14:28:30 +00:00
|
|
|
|
2025-01-29 20:28:22 +00:00
|
|
|
logger.info('Adding Wide Angle Analytics (useWideAngle) import')
|
|
|
|
addImportsDir(resolver.resolve('./runtime/composables'))
|
2023-05-18 12:33:46 +00:00
|
|
|
|
2025-01-29 20:28:22 +00:00
|
|
|
logger.info('Adding Wide Angle Analytics runtime plugin')
|
|
|
|
addPlugin(resolver.resolve('./runtime/plugin.client'))
|
2023-05-18 12:33:46 +00:00
|
|
|
|
2025-01-29 20:28:22 +00:00
|
|
|
},
|
2023-05-14 15:25:44 +00:00
|
|
|
})
|