Fix Plausible loading for authenticated users

Return early within the Plausible if the user is authenticated so that
it doesn't pick up when I'm adding or editing content on the site.

Though the role is configured in the Plausible module's admin form, the
conditions in the code don't exclude it. I'll look into this further and
submit a patch upstream along with some tests.

References #350
This commit is contained in:
Oliver Davies 2021-01-29 12:53:50 +00:00
parent 24f1fd5673
commit dcf180a651
3 changed files with 28 additions and 5 deletions

View file

@ -114,6 +114,9 @@
] ]
}, },
"patches": { "patches": {
"drupal/plausible": {
"Return early if user is not anonymous": "tools/patches/plausible/return-if-authenticated.patch"
}
} }
} }
} }

10
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "fe496bbcb4eef8b520c250b2c4d70d83", "content-hash": "6aa7c4e54ecdea98cfca107f6be3cc9e",
"packages": [ "packages": [
{ {
"name": "asm89/stack-cors", "name": "asm89/stack-cors",
@ -8229,12 +8229,12 @@
"version": "1.9.1", "version": "1.9.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/webmozart/assert.git", "url": "https://github.com/webmozarts/assert.git",
"reference": "bafc69caeb4d49c39fd0779086c03a3738cbb389" "reference": "bafc69caeb4d49c39fd0779086c03a3738cbb389"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/webmozart/assert/zipball/bafc69caeb4d49c39fd0779086c03a3738cbb389", "url": "https://api.github.com/repos/webmozarts/assert/zipball/bafc69caeb4d49c39fd0779086c03a3738cbb389",
"reference": "bafc69caeb4d49c39fd0779086c03a3738cbb389", "reference": "bafc69caeb4d49c39fd0779086c03a3738cbb389",
"shasum": "" "shasum": ""
}, },
@ -8272,8 +8272,8 @@
"validate" "validate"
], ],
"support": { "support": {
"issues": "https://github.com/webmozart/assert/issues", "issues": "https://github.com/webmozarts/assert/issues",
"source": "https://github.com/webmozart/assert/tree/master" "source": "https://github.com/webmozarts/assert/tree/1.9.1"
}, },
"time": "2020-07-08T17:02:28+00:00" "time": "2020-07-08T17:02:28+00:00"
}, },

View file

@ -0,0 +1,20 @@
diff --git a/plausible.module b/plausible.module
index ce5a826..aa78dc5 100644
--- a/plausible.module
+++ b/plausible.module
@@ -16,9 +16,14 @@ use Drupal\plausible\Component\Render\PlausibleJavaScriptSnippet;
function plausible_page_attachments(array &$attachments) {
$account = \Drupal::currentUser();
- if (! (_plausible_visibility_pages() && _plausible_visibility_roles($account))) {
+ if (!_plausible_visibility_pages()) {
return;
}
+
+ if ($account->isAuthenticated()) {
+ return;
+ }
+
$config = \Drupal::config('plausible.settings');
$attachments['#attached']['html_head'][] = [
[