Skip to content

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

ScriptV2: Support `meta` only in legacy scripts (#5492)

Karl-Aksel Puulmannc7779e2f333c
diff --git a/lib/plausible/ingestion/request.ex b/lib/plausible/ingestion/request.ex
index efbccc5320..95831febe0 100644
--- a/lib/plausible/ingestion/request.ex
+++ b/lib/plausible/ingestion/request.ex
@@ -24,7 +24,6 @@ defmodule Plausible.Ingestion.Request do
use Ecto.Schema
use Plausible
- require Logger
alias Ecto.Changeset
@max_url_size 2_000
@@ -231,13 +230,6 @@ defmodule Plausible.Ingestion.Request do
|> Enum.take(@max_props)
|> Map.new()
- # Temporary instrumentation to see if `m`/`meta` field was used.
- if request_body["m"] || request_body["meta"] do
- Logger.warning(
- "Ingestion: request body contains meta field. domain=#{request_body["d"] || request_body["domain"]}"
- )
- end
-
changeset
|> Changeset.put_change(:props, props)
|> validate_props()
diff --git a/tracker/npm_package/CHANGELOG.md b/tracker/npm_package/CHANGELOG.md
index db718beaf9..5e3c9903f2 100644
--- a/tracker/npm_package/CHANGELOG.md
+++ b/tracker/npm_package/CHANGELOG.md
@@ -9,3 +9,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Support for `config.transformRequest`
- Support for passing `url` as option when calling `track`
+- Drop support for `meta` argument.
diff --git a/tracker/npm_package/package.json b/tracker/npm_package/package.json
index e114c9f911..ad80d17e28 100644
--- a/tracker/npm_package/package.json
+++ b/tracker/npm_package/package.json
@@ -1,6 +1,6 @@
{
"name": "macobo-test-tracker",
- "version": "0.2.0",
+ "version": "0.2.1",
"description": "Plausible Analytics official frontend tracking library",
"scripts": {
"test": "echo \"Error: Testing done in the tracker folder\" && exit 1"
diff --git a/tracker/package.json b/tracker/package.json
index b5d9a13f8e..e1c766bfdc 100644
--- a/tracker/package.json
+++ b/tracker/package.json
@@ -1,5 +1,5 @@
{
- "tracker_script_version": 17,
+ "tracker_script_version": 18,
"type": "module",
"scripts": {
"deploy": "node compile.js",
diff --git a/tracker/src/track.js b/tracker/src/track.js
index 18ad2a59c8..6bdd13792e 100644
--- a/tracker/src/track.js
+++ b/tracker/src/track.js
@@ -64,7 +64,7 @@ export function track(eventName, options) {
payload.d = config.domain
payload.r = document.referrer || null
- if (options && options.meta) {
+ if (COMPILE_PLAUSIBLE_LEGACY_VARIANT && options && options.meta) {
payload.m = JSON.stringify(options.meta)
}
if (options && options.props) {
diff --git a/tracker/test/fixtures/legacy-custom-properties.html b/tracker/test/fixtures/legacy-custom-properties.html
new file mode 100644
index 0000000000..50a194e063
--- /dev/null
+++ b/tracker/test/fixtures/legacy-custom-properties.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html lang="en">
+
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <meta http-equiv="X-UA-Compatible" content="ie=edge">
+ <title>Plausible Playwright tests</title>
+ <script defer src="/tracker/js/plausible.local.pageview-props.js"></script>
+</head>
+
+<body>
+ <button id="custom-props-button" onclick="plausible('Props event', { props: { type: 'props' } })">Custom props</button>
+ <button id="custom-meta-button" onclick="plausible('Meta event', { meta: { type: 'meta' } })">Custom meta</button>
+</body>
+</html>
diff --git a/tracker/test/fixtures/legacy-pageview-properties.html b/tracker/test/fixtures/legacy-pageview-properties.html
new file mode 100644
index 0000000000..2bea11c1bf
--- /dev/null
+++ b/tracker/test/fixtures/legacy-pageview-properties.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html lang="en">
+
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <meta http-equiv="X-UA-Compatible" content="ie=edge">
+ <title>Plausible Playwright tests</title>
+ <script defer event-author="John" event-foo="bar" src="/tracker/js/plausible.local.pageview-props.js"></script>
+</head>
+
+<body>
+ <button id="custom-event-button" onclick="plausible('Custom event', { props: { author: 'Karl' } })">Custom event</button>
+</body>
+</html>
diff --git a/tracker/test/legacy-custom-properties.spec.js b/tracker/test/legacy-custom-properties.spec.js
new file mode 100644
index 0000000000..65db5ed6b8
--- /dev/null
+++ b/tracker/test/legacy-custom-properties.spec.js
@@ -0,0 +1,46 @@
+import {
+ expectPlausibleInAction,
+ isPageviewEvent
+} from './support/test-utils'
+import { test } from '@playwright/test'
+
+test.describe('legacy custom properties support', () => {
+ test('sends custom properties via dom attributes', async ({ page }) => {
+ await expectPlausibleInAction(page, {
+ action: async () => {
+ await page.goto('/legacy-pageview-properties.html')
+ await page.click('#custom-event-button')
+ },
+ expectedRequests: [
+ { n: 'pageview', p: { author: 'John', foo: 'bar' } },
+ { n: 'Custom event', p: { author: 'Karl', foo: 'bar' } }
+ ]
+ })
+ })
+
+ test('sends custom properties via `props`', async ({ page }) => {
+ await expectPlausibleInAction(page, {
+ action: async () => {
+ await page.goto('/legacy-custom-properties.html')
+ await page.click('#custom-props-button')
+ },
+ expectedRequests: [
+ { n: 'Props event', p: { type: 'props' } }
+ ],
+ shouldIgnoreRequest: isPageviewEvent
+ })
+ })
+
+ test('sends custom properties via `meta`', async ({ page }) => {
+ await expectPlausibleInAction(page, {
+ action: async () => {
+ await page.goto('/legacy-custom-properties.html')
+ await page.click('#custom-meta-button')
+ },
+ expectedRequests: [
+ { n: 'Meta event', m: '{"type":"meta"}' }
+ ],
+ shouldIgnoreRequest: isPageviewEvent
+ })
+ })
+})