nuxt-umami
Advanced tools
+9
-11
@@ -21,14 +21,12 @@ import type { PreflightResult } from './types'; | ||
| function screamer(id: ErrorId, raw?: any) { | ||
| const { level, text } = warnings[id]; | ||
| // eslint-disable-next-line no-console | ||
| console[level](`[UMAMI]: ${text}`, '\n'); | ||
| // eslint-disable-next-line no-console | ||
| raw && (console[level](raw)); | ||
| } | ||
| const helloDebugger = process.env.NODE_ENV === 'production' | ||
| ? (id: ErrorId, raw?: any) => {} | ||
| : (id: ErrorId, raw?: any) => { | ||
| const { level, text } = warnings[id]; | ||
| // eslint-disable-next-line no-console | ||
| console[level](`[UMAMI]: ${text}`, '\n'); | ||
| // eslint-disable-next-line no-console | ||
| raw && (console[level](raw)); | ||
| }; | ||
| function silencio(id: ErrorId, raw?: any) {} | ||
| const helloDebugger = process.env.NODE_ENV === 'production' ? silencio : screamer; | ||
| export { helloDebugger }; |
@@ -26,10 +26,2 @@ interface BasicPayload { | ||
| interface PreflightArgs { | ||
| ignoreDnt?: boolean | ||
| domains?: string | ||
| id?: string | ||
| host?: string | ||
| ignoreLocal?: boolean | ||
| } | ||
| interface ServerPayload { | ||
@@ -53,5 +45,4 @@ type: PayloadType | ||
| ServerPayload, | ||
| PreflightArgs, | ||
| PreflightResult, | ||
| GetPayloadReturn, | ||
| }; |
+31
-6
| import type { | ||
| GetPayloadReturn, | ||
| PartialPayload, | ||
| PreflightArgs, | ||
| PreflightResult, | ||
@@ -28,5 +27,31 @@ ServerPayload, | ||
| function preflight( | ||
| { ignoreDnt, domains, id, host, ignoreLocal }: PreflightArgs, | ||
| ): PreflightResult { | ||
| const umConfig = computed(() => { | ||
| const { public: { umamiHost, umamiId } } = useRuntimeConfig(); | ||
| const { | ||
| umami: { | ||
| host = '', | ||
| id = '', | ||
| domains = '', | ||
| ignoreDnt = true, | ||
| ignoreLocalhost: ignoreLocal = false, | ||
| autoTrack = true, | ||
| version = 1, | ||
| }, | ||
| } = useAppConfig(); | ||
| return { | ||
| host: umamiHost || host, | ||
| id: umamiId || id, | ||
| domains, | ||
| ignoreDnt, | ||
| ignoreLocal, | ||
| autoTrack, | ||
| version, | ||
| }; | ||
| }); | ||
| function preflight(): PreflightResult { | ||
| const { ignoreDnt, domains, id, host, ignoreLocal } = umConfig.value; | ||
| if (typeof window === 'undefined') { | ||
@@ -99,3 +124,3 @@ return 'ssr'; | ||
| async function collect(load: ServerPayload) { | ||
| const { umami: { host, version } } = useAppConfig(); | ||
| const { host, version } = umConfig.value; | ||
| const root = new URL(host); | ||
@@ -122,2 +147,2 @@ const branch = version === 2 ? 'api/send' : 'api/collect'; | ||
| export { preflight, getPayload, assert, collect }; | ||
| export { preflight, getPayload, assert, collect, umConfig }; |
@@ -0,5 +1,6 @@ | ||
| import { umConfig } from '../internal/utils'; | ||
| import { umTrackView } from '../utils/umami'; | ||
| export default defineNuxtRouteMiddleware((to) => { | ||
| const { umami: { autoTrack } = {} } = useAppConfig(); | ||
| const { autoTrack } = umConfig.value; | ||
@@ -6,0 +7,0 @@ if (autoTrack) { |
+6
-0
@@ -13,2 +13,8 @@ export default defineNuxtConfig({ | ||
| }, | ||
| runtimeConfig: { | ||
| public: { | ||
| umamiHost: '', | ||
| umamiId: '', | ||
| }, | ||
| }, | ||
| }); | ||
@@ -15,0 +21,0 @@ |
+1
-1
| { | ||
| "name": "nuxt-umami", | ||
| "type": "module", | ||
| "version": "2.0.3", | ||
| "version": "2.0.4-beta.1", | ||
| "description": "Integrate Umami Analytics into Nuxt", | ||
@@ -6,0 +6,0 @@ "author": "ML <me.mlaure@gmail.com>", |
+4
-0
@@ -26,2 +26,6 @@ # Nuxt Umami <sup>@next<sup> | ||
| ### 🚀 Try it online | ||
| <a href="https://stackblitz.com/edit/nuxt-umami-next"><img src="https://developer.stackblitz.com/img/open_in_stackblitz.svg" alt="Open in StackBlitz"></a> | ||
| ### Step 1: Install and add to Nuxt | ||
@@ -28,0 +32,0 @@ |
+5
-23
@@ -1,2 +0,2 @@ | ||
| import { assert, collect, getPayload, preflight } from '../internal/utils'; | ||
| import { collect, getPayload, preflight, umConfig } from '../internal/utils'; | ||
| import type { EventData, EventPayload, ViewPayload } from '../internal/types'; | ||
@@ -13,12 +13,4 @@ import { helloDebugger } from '../internal/debug'; | ||
| function trackView(url?: string, referrer?: string): void { | ||
| const { | ||
| umami: { | ||
| id, host, domains, | ||
| ignoreDnt = false, | ||
| ignoreLocalhost: ignoreLocal = false, | ||
| } = {}, | ||
| } = useAppConfig(); | ||
| const check = preflight(); | ||
| const check = preflight({ domains, ignoreDnt, id, host, ignoreLocal }); | ||
| if (check === 'ssr') { | ||
@@ -33,4 +25,3 @@ return; | ||
| assert(typeof id === 'string'); | ||
| const { id } = umConfig.value; | ||
| const { pageReferrer, pageUrl, payload } = getPayload(); | ||
@@ -58,12 +49,4 @@ | ||
| function trackEvent(eventName: string, eventData?: EventData) { | ||
| const { | ||
| umami: { | ||
| id, host, domains, | ||
| ignoreDnt = false, | ||
| ignoreLocalhost: ignoreLocal = false, | ||
| } = {}, | ||
| } = useAppConfig(); | ||
| const check = preflight(); | ||
| const check = preflight({ domains, ignoreDnt, host, id, ignoreLocal }); | ||
| if (check === 'ssr') { | ||
@@ -78,4 +61,3 @@ return; | ||
| assert(typeof id === 'string'); | ||
| const { id } = umConfig.value; | ||
| const { payload } = getPayload(); | ||
@@ -82,0 +64,0 @@ const name = eventName || '#unknown-event'; |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Unpublished package
Supply chain riskPackage version was not found on the registry. It may exist on a different registry and need to be configured to pull from that registry.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
16249
1.23%345
1.77%145
2.84%2
100%2
100%