nuxt-umami
Advanced tools
Comparing version 2.6.0 to 2.6.1
@@ -36,2 +36,4 @@ interface BasicPayload { | ||
type FetchResult = Promise<{ ok: boolean }>; | ||
export type { | ||
@@ -45,2 +47,3 @@ EventData, | ||
PreflightResult, | ||
FetchResult, | ||
}; |
import type { | ||
FetchResult, | ||
PartialPayload, | ||
@@ -148,4 +149,8 @@ PreflightResult, | ||
async function collect(load: ServerPayload) { | ||
fetch(endpoint.value, { | ||
function earlyPromise(ok: boolean): FetchResult { | ||
return Promise.resolve({ ok }); | ||
} | ||
async function collect(load: ServerPayload): FetchResult { | ||
return fetch(endpoint.value, { | ||
method: 'POST', | ||
@@ -158,13 +163,15 @@ headers: { | ||
}) | ||
.then(async (res) => { | ||
if (res && !res.ok) | ||
return helloDebugger.value('err-collect', res); | ||
.then(async (response) => { | ||
if (!response.ok) | ||
throw new Error('Network error', { cause: response }); | ||
cache.value = await res.text(); | ||
cache.value = await response.text(); | ||
return { ok: true }; | ||
}) | ||
.catch((err) => { | ||
helloDebugger.value('err-collect', err); | ||
return { ok: false }; | ||
}); | ||
} | ||
export { isValidString, preflight, getPayload, collect, umConfig, helloDebugger }; | ||
export { isValidString, preflight, getPayload, collect, earlyPromise, umConfig, helloDebugger }; |
{ | ||
"name": "nuxt-umami", | ||
"type": "module", | ||
"version": "2.6.0", | ||
"version": "2.6.1", | ||
"description": "Integrate Umami Analytics into Nuxt", | ||
@@ -44,9 +44,9 @@ "author": "ML <me.mlaure@gmail.com>", | ||
"devDependencies": { | ||
"@antfu/eslint-config": "~2.7.0", | ||
"@types/node": "^20.11.24", | ||
"bumpp": "^9.3.0", | ||
"eslint": "^8.57.0", | ||
"nuxt": "^3.10.3", | ||
"typescript": "^5.3.3" | ||
"@antfu/eslint-config": "~2.16.0", | ||
"@types/node": "^20.12.7", | ||
"bumpp": "^9.4.0", | ||
"eslint": "^9.1.1", | ||
"nuxt": "^3.11.2", | ||
"typescript": "^5.4.5" | ||
} | ||
} |
@@ -158,2 +158,12 @@ # Nuxt Umami | ||
### Method Return | ||
Both `umTrackEvent` and `umTrackView` return a Promise with an `ok` status that you can await or chain, `Promise<{ok: boolean}>`. | ||
```ts | ||
umTrackView().then(res => console.log(res.ok)); | ||
umTrackView().then(({ ok }) => console.log(ok)); | ||
``` | ||
### Vue Directive | ||
@@ -160,0 +170,0 @@ |
@@ -1,3 +0,3 @@ | ||
import { collect, getPayload, helloDebugger, isValidString, preflight, umConfig } from '../internal/utils'; | ||
import type { EventData, EventPayload, ViewPayload } from '../internal/types'; | ||
import { collect, earlyPromise, getPayload, helloDebugger, isValidString, preflight, umConfig } from '../internal/utils'; | ||
import type { EventData, EventPayload, FetchResult, ViewPayload } from '../internal/types'; | ||
@@ -11,11 +11,11 @@ /** | ||
*/ | ||
function trackView(url?: string, referrer?: string): void { | ||
function trackView(url?: string, referrer?: string): FetchResult { | ||
const check = preflight.value; | ||
if (check === 'ssr') | ||
return; | ||
return earlyPromise(false); | ||
if (check !== true) { | ||
helloDebugger.value(`err-${check}`); | ||
return; | ||
return earlyPromise(false); | ||
} | ||
@@ -26,3 +26,3 @@ | ||
void collect( | ||
return collect( | ||
{ | ||
@@ -47,11 +47,11 @@ type: version === 2 ? 'event' : 'pageview', | ||
*/ | ||
function trackEvent(eventName: string, eventData?: EventData) { | ||
function trackEvent(eventName: string, eventData?: EventData): FetchResult { | ||
const check = preflight.value; | ||
if (check === 'ssr') | ||
return; | ||
return earlyPromise(false); | ||
if (check !== true) { | ||
helloDebugger.value(`err-${check}`); | ||
return; | ||
return earlyPromise(false); | ||
} | ||
@@ -74,12 +74,6 @@ | ||
const eventObj = version === 2 | ||
? { | ||
name, | ||
data, | ||
} | ||
: { | ||
event_name: name, | ||
event_data: data, | ||
}; | ||
? { name, data } | ||
: { event_name: name, event_data: data }; | ||
void collect({ | ||
return collect({ | ||
type: 'event', | ||
@@ -86,0 +80,0 @@ payload: { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24568
456
219