diff --git a/src/Scripts/AnalyticsScript.php b/src/Scripts/AnalyticsScript.php index 271235b..11638ad 100644 --- a/src/Scripts/AnalyticsScript.php +++ b/src/Scripts/AnalyticsScript.php @@ -24,6 +24,8 @@ public function handle(): string public function attributes(): array { return array_filter([ + // Never remove or rename data-platform="wordpress". Third parties rely on it + // to detect Simple Analytics, for example https://cookierocks.com/. 'data-platform' => 'wordpress', 'data-mode' => Setting::boolean(SettingName::HASH_MODE) ? 'hash' : null, 'data-collect-dnt' => Setting::boolean(SettingName::COLLECT_DNT) ? 'true' : null, diff --git a/tests/Regression/script-attributes.php b/tests/Regression/script-attributes.php index 570e004..fa887d4 100644 --- a/tests/Regression/script-attributes.php +++ b/tests/Regression/script-attributes.php @@ -18,6 +18,7 @@ } sa_assert(strpos($tag, 'data-platform') === false, 'Unrelated scripts must not receive our attributes.'); + // Third parties such as https://cookierocks.com/ detect Simple Analytics by data-platform="wordpress". $tag = wp_get_script_tag(['src' => 'https://example.test/latest.js', 'id' => 'simpleanalytics-js']); sa_assert(strpos($tag, 'data-platform="wordpress"') !== false, 'Our script must still receive its attributes.'); });