Skip to content

Commit

Permalink
New: Add additional option to disable tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnitto committed Jan 25, 2021
1 parent 257079e commit e0fb931
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 1 deletion.
12 changes: 12 additions & 0 deletions Configuration/Routes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
- name: 'Set cookie for disable tracking'
uriPattern: '{node}~/disable-tracking'
defaults:
'@package': 'Neos.Neos'
'@controller': 'Frontend\Node'
'@action': 'show'
'disablePlausibleTracking': true
routeParts:
node:
handler: 'Neos\Neos\Routing\FrontendNodeRoutePartHandlerInterface'
options:
onlyMatchSiteNodes: true
5 changes: 5 additions & 0 deletions Configuration/Settings.Neos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ Neos:
Fusion:
defaultContext:
Carbon.Plausible: 'Carbon\Plausible\EelHelper\PlausibleHelper'
Flow:
mvc:
routes:
'Carbon.Plausible':
position: 'start'
Neos:
fusion:
autoInclude:
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ This package contains two mixins:

### Set cookie for disabling tracking

Every editor can easily set a cookie to disable tracking for the current browser.
By default, Plausible Analytics tracks every visitor to your website. When you're working on your site, you might not want to record your own visits and page views. To block your (and your co-workers) page views from your Plausible Analytics stats dashboard, you have the following options:

- Go to `your-domain.tld/~/disable-tracking`. This sets the cookie and redirects the visitor to the homepage. Great for people without access to the Neos Backend.
- As an Administrator, you can enable/disable the cookie also in the Plausible administration module: `your-domain.tld/neos/administration/plausible`
- Editors can also enable/disable the cookie by clicking a button in the primary toolbar:

![set cookie in the inspector]

Expand Down
39 changes: 39 additions & 0 deletions Resources/Private/Fusion/Document/SetCookie.fusion
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

prototype(Carbon.Plausible:Document.SetCookie) < prototype(Neos.Fusion:Component) {
setCookie = "var domain=document.location.host.split('.').slice(-2).join('.');document.cookie='disabledPlausible=true;path=/; max-age=31536000000;domain='+domain;setTimeout(function(){window.location='/'},5000);"
domain = Carbon.Plausible:Component.RequestMainDomain
title = ${Translation.translate('disableCookie', 'Tracking for {0} from this browser is now disabled', [this.domain], null, 'Carbon.Plausible')}
renderer = Neos.Fusion:Http.Message {
doctype = '<!DOCTYPE html>'
content = afx`
<html>
<head>
<meta charset='UTF-8' />
<title>{props.title}</title>
<meta name='robots' content='noindex,nofollow' />
<script>{props.setCookie}</script>
</head>
<body style='display:flex;align-items:center;min-height:90vh;'>
<h1 style='margin:1em auto;max-width:30ch;text-align:center;font-family:system-ui,-apple-system,Segoe UI,Roboto,Cantarell,Noto Sans,sans-serif;'>{props.title}</h1>
</body>
</html>
`
}

@cache {
mode = 'cached'
entryIdentifier {
site = ${site}
plausible = 'CarbonPlausibleSetCookie'
}
entryTags {
1 = ${Neos.Caching.nodeTag(site)}
}
}
@exceptionHandler = 'Neos\\Neos\\Fusion\\ExceptionHandlers\\PageHandler'
}

root.disableTracking {
condition = ${request.arguments.disablePlausibleTracking == true && !request.httpRequest.cookieParams.disabledPlausible}
renderer = Carbon.Plausible:Document.SetCookie
}
4 changes: 4 additions & 0 deletions Resources/Private/Translations/de/Main.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
<source>Tracking</source>
<target>Tracking</target>
</trans-unit>
<trans-unit id="disableCookie" xml:space="preserve">
<source>Tracking for {0} from this browser is now disabled</source>
<target>Tracking von {0} ist in diesem Browser nun deaktiviert</target>
</trans-unit>
</body>
</file>
</xliff>
4 changes: 4 additions & 0 deletions Resources/Private/Translations/en/Main.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
<source>Tracking</source>
<target>Tracking</target>
</trans-unit>
<trans-unit id="disableCookie" xml:space="preserve">
<source>Tracking for {0} from this browser is now disabled</source>
<target>Tracking for {0} from this browser is now disabled</target>
</trans-unit>
</body>
</file>
</xliff>

0 comments on commit e0fb931

Please sign in to comment.