Fix tracker bug - call callback function when ignoring event (#2947)

* call callback function when ignoring event

* update changelog
This commit is contained in:
RobertJoonas 2023-05-19 13:27:11 +02:00 committed by GitHub
parent 34a6b984c7
commit e27e29250b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 6 deletions

View File

@ -11,6 +11,7 @@ All notable changes to this project will be documented in this file.
- Ability to change domain for existing site (requires numeric IDs data migration, instructions will be provided separately) UI + API (`PUT /api/v1/sites`)
### Fixed
- Fix tracker bug - call callback function even when event is ignored
- Make goal-filtered CSV export return only unique_conversions timeseries in the 'visitors.csv' file
- Stop treating page filter as an entry page filter
- City report showing N/A instead of city names with imported data plausible/analytics#2675

View File

@ -11,8 +11,9 @@
{{/if}}
var endpoint = scriptEl.getAttribute('data-api') || defaultEndpoint(scriptEl)
function warn(reason) {
console.warn('Ignoring Event: ' + reason);
function onIgnoredEvent(reason, options) {
if (reason) console.warn('Ignoring Event: ' + reason);
options && options.callback && options.callback()
}
function defaultEndpoint(el) {
@ -29,12 +30,16 @@
function trigger(eventName, options) {
{{#unless local}}
if (/^localhost$|^127(\.[0-9]+){0,2}\.[0-9]+$|^\[::1?\]$/.test(location.hostname) || location.protocol === 'file:') return warn('localhost');
if (window._phantom || window.__nightmare || window.navigator.webdriver || window.Cypress) return;
if (/^localhost$|^127(\.[0-9]+){0,2}\.[0-9]+$|^\[::1?\]$/.test(location.hostname) || location.protocol === 'file:') {
return onIgnoredEvent('localhost', options)
}
if (window._phantom || window.__nightmare || window.navigator.webdriver || window.Cypress) {
return onIgnoredEvent(null, options)
}
{{/unless}}
try {
if (window.localStorage.plausible_ignore === 'true') {
return warn('localStorage flag')
return onIgnoredEvent('localStorage flag', options)
}
} catch (e) {
@ -47,7 +52,7 @@
var isIncluded = !dataIncludeAttr || (dataIncludeAttr && dataIncludeAttr.split(',').some(pathMatches))
var isExcluded = dataExcludeAttr && dataExcludeAttr.split(',').some(pathMatches)
if (!isIncluded || isExcluded) return warn('exclusion rule')
if (!isIncluded || isExcluded) return onIgnoredEvent('exclusion rule', options)
}
function pathMatches(wildcardPath) {