@@ -22,14 +22,15 @@ import { removeTrailingSlash } from '../lib/url';
22
22
const autoTrack = attr ( 'data-auto-track' ) !== 'false' ;
23
23
const dnt = attr ( 'data-do-not-track' ) ;
24
24
const useCache = attr ( 'data-cache' ) ;
25
+ const cssEvents = attr ( 'data-css-events' ) !== 'false' ;
25
26
const domain = attr ( 'data-domains' ) || '' ;
26
27
const domains = domain . split ( ',' ) . map ( n => n . trim ( ) ) ;
27
28
28
29
const eventClass = / ^ u m a m i - - ( [ a - z ] + ) - - ( [ \w ] + [ \w - ] * ) $ / ;
29
30
const eventSelect = "[class*='umami--']" ;
30
31
const cacheKey = 'umami.cache' ;
31
32
32
- const disableTracking = ( ) =>
33
+ const trackingDisabled = ( ) =>
33
34
( localStorage && localStorage . getItem ( 'umami.disabled' ) ) ||
34
35
( dnt && doNotTrack ( ) ) ||
35
36
( domain && ! domains . includes ( hostname ) ) ;
@@ -75,7 +76,7 @@ import { removeTrailingSlash } from '../lib/url';
75
76
} ;
76
77
77
78
const collect = ( type , payload ) => {
78
- if ( disableTracking ( ) ) return ;
79
+ if ( trackingDisabled ( ) ) return ;
79
80
80
81
post (
81
82
`${ root } /api/collect` ,
@@ -150,14 +151,6 @@ import { removeTrailingSlash } from '../lib/url';
150
151
} ) ;
151
152
} ;
152
153
153
- const monitorMutate = mutations => {
154
- mutations . forEach ( mutation => {
155
- const element = mutation . target ;
156
- addEvent ( element ) ;
157
- addEvents ( element ) ;
158
- } ) ;
159
- } ;
160
-
161
154
/* Handle history changes */
162
155
163
156
const handlePush = ( state , title , url ) => {
@@ -177,6 +170,19 @@ import { removeTrailingSlash } from '../lib/url';
177
170
}
178
171
} ;
179
172
173
+ const observeDocument = ( ) => {
174
+ const monitorMutate = mutations => {
175
+ mutations . forEach ( mutation => {
176
+ const element = mutation . target ;
177
+ addEvent ( element ) ;
178
+ addEvents ( element ) ;
179
+ } ) ;
180
+ } ;
181
+
182
+ const observer = new MutationObserver ( monitorMutate ) ;
183
+ observer . observe ( document , { childList : true , subtree : true } ) ;
184
+ } ;
185
+
180
186
/* Global */
181
187
182
188
if ( ! window . umami ) {
@@ -189,17 +195,18 @@ import { removeTrailingSlash } from '../lib/url';
189
195
190
196
/* Start */
191
197
192
- if ( autoTrack && ! disableTracking ( ) ) {
198
+ if ( autoTrack && ! trackingDisabled ( ) ) {
193
199
history . pushState = hook ( history , 'pushState' , handlePush ) ;
194
200
history . replaceState = hook ( history , 'replaceState' , handlePush ) ;
195
201
196
202
const update = ( ) => {
197
203
if ( document . readyState === 'complete' ) {
198
- addEvents ( document ) ;
199
204
trackView ( ) ;
200
205
201
- const observer = new MutationObserver ( monitorMutate ) ;
202
- observer . observe ( document , { childList : true , subtree : true } ) ;
206
+ if ( cssEvents ) {
207
+ addEvents ( document ) ;
208
+ observeDocument ( ) ;
209
+ }
203
210
}
204
211
} ;
205
212
0 commit comments