@@ -4,10 +4,12 @@ import { boolean, object, optional, string } from '#nuxt-scripts-validator'
4
4
import type { RegistryScriptInput } from '#nuxt-scripts'
5
5
6
6
export const MatomoAnalyticsOptions = object ( {
7
- matomoUrl : string ( ) , // site is required
7
+ matomoUrl : optional ( string ( ) ) ,
8
8
siteId : string ( ) ,
9
+ trackerUrl : optional ( string ( ) ) ,
9
10
trackPageView : optional ( boolean ( ) ) ,
10
11
enableLinkTracking : optional ( boolean ( ) ) ,
12
+ disableCookies : optional ( boolean ( ) ) ,
11
13
} )
12
14
13
15
export type MatomoAnalyticsInput = RegistryScriptInput < typeof MatomoAnalyticsOptions , false , false , false >
@@ -23,7 +25,7 @@ declare global {
23
25
export function useScriptMatomoAnalytics < T extends MatomoAnalyticsApi > ( _options ?: MatomoAnalyticsInput ) {
24
26
return useRegistryScript < T , typeof MatomoAnalyticsOptions > ( 'matomoAnalytics' , options => ( {
25
27
scriptInput : {
26
- src : withBase ( `/matomo.js` , withHttps ( options ?. matomoUrl ) ) ,
28
+ src : withBase ( `/matomo.js` , withHttps ( options ?. matomoUrl || '' ) ) ,
27
29
crossorigin : false ,
28
30
} ,
29
31
schema : import . meta. dev ? MatomoAnalyticsOptions : undefined ,
@@ -48,7 +50,14 @@ export function useScriptMatomoAnalytics<T extends MatomoAnalyticsApi>(_options?
48
50
if ( options ?. enableLinkTracking ) {
49
51
_paq . push ( [ 'enableLinkTracking' ] )
50
52
}
51
- _paq . push ( [ 'setTrackerUrl' , withBase ( `/matomo.php` , withHttps ( options ?. matomoUrl ) ) ] )
53
+
54
+ if ( options ?. disableCookies ) {
55
+ _paq . push ( [ 'disableCookies' ] )
56
+ }
57
+
58
+ if ( options ?. trackerUrl || options ?. matomoUrl ) {
59
+ _paq . push ( [ 'setTrackerUrl' , options ?. trackerUrl ? withHttps ( options . trackerUrl ) : withBase ( `/matomo.php` , withHttps ( options ?. matomoUrl || '' ) ) ] )
60
+ }
52
61
_paq . push ( [ 'setSiteId' , options ?. siteId || '1' ] )
53
62
} ,
54
63
} ) , _options )
0 commit comments