Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

Improve tagged events (#2880)

RobertJoonas020e155fdf0c
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7970881eb5..05669be754 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file.
## Unreleased
### Added
+- Ability to use '--' instead of '=' sign in the `tagged-events` classnames
- 'Last updated X seconds ago' info to 'current visitors' tooltips
- Add support for more Bamboo adapters, i.e. `Bamboo.MailgunAdapter`, `Bamboo.MandrillAdapter`, `Bamboo.SendGridAdapter` plausible/analytics#2649
- Ability to change domain for existing site (requires numeric IDs data migration, instructions will be provided separately) UI + API (`PUT /api/v1/sites`)
diff --git a/tracker/src/customEvents.js b/tracker/src/customEvents.js
index 7d3c563aa8..98ef7db307 100644
--- a/tracker/src/customEvents.js
+++ b/tracker/src/customEvents.js
@@ -104,11 +104,11 @@ function getTaggedEventAttributes(htmlElement) {
for (var i = 0; i < classList.length; i++) {
var className = classList.item(i)
- var matchList = className.match(/plausible-event-(.+)=(.+)/)
+ var matchList = className.match(/plausible-event-(.+)(=|--)(.+)/)
if (!matchList) { continue }
var key = matchList[1]
- var value = matchList[2].replace(/\+/g, ' ')
+ var value = matchList[3].replace(/\+/g, ' ')
if (key.toLowerCase() === 'name') {
eventAttrs.name = value
@@ -180,7 +180,7 @@ function isTagged(element) {
var classList = element && element.classList
if (classList) {
for (var i = 0; i < classList.length; i++) {
- if (classList.item(i).match(/plausible-event-name=(.+)/)) { return true }
+ if (classList.item(i).match(/plausible-event-name(=|--)(.+)/)) { return true }
}
}
return false
diff --git a/tracker/test/fixtures/tagged-event.html b/tracker/test/fixtures/tagged-event.html
index c6b436e6b7..61b8b8cc29 100644
--- a/tracker/test/fixtures/tagged-event.html
+++ b/tracker/test/fixtures/tagged-event.html
@@ -12,7 +12,7 @@
<body>
<a id="link"
- class="plausible-event-name=Payment+Complete should ignore-this plausible-event-amount=100 plausible-event-method=Credit+Card"
+ class="plausible-event-name--Payment+Complete should ignore-this plausible-event-amount--100 plausible-event-method--Credit+Card"
href="https://awesome.website.com/payment/">tagged link</a>
<form class="plausible-event-name=Signup plausible-event-type=Newsletter"
@@ -58,6 +58,7 @@
</span>
+
<script>
// Dynamically add a tagged element to DOM after one second
setTimeout(function () {