From e27e29250b6169b96f73576ab37e6278afb21bc3 Mon Sep 17 00:00:00 2001 From: RobertJoonas <56999674+RobertJoonas@users.noreply.github.com> Date: Fri, 19 May 2023 13:27:11 +0200 Subject: [PATCH] Fix tracker bug - call callback function when ignoring event (#2947) * call callback function when ignoring event * update changelog --- CHANGELOG.md | 1 + tracker/src/plausible.js | 17 +++++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f56d780f..59b8abcbf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/tracker/src/plausible.js b/tracker/src/plausible.js index 4a0645a67..b89da3bdf 100644 --- a/tracker/src/plausible.js +++ b/tracker/src/plausible.js @@ -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) {