Skip to content

Commit

Permalink
New: Add exclusions option (#3)
Browse files Browse the repository at this point in the history
* New: Add exclusions option

* Fix: Fix typo

* Docs: Update Screenshots

* Chore: Change order of features

It has now the same order as in https://github.com/plausible/analytics/blob/master/lib/plausible_web/plugs/tracker.ex

* Docs: Update Readme

* Fix: showMessage function

* Fix: Mixin names

* New: Better behaviour in the inspector

* New: Add german language and add CSS to module

* New: Minify inline js and use own helper to get main domain

* New: Add button to toolbar to enable or disable tracking

* Docs: Update Readme
  • Loading branch information
jonnitto authored Jan 26, 2021
1 parent e0fb931 commit 58315cb
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions Configuration/Settings.Carbon.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Carbon:
host: null
outboundLinks: false
hashBasedRouting: false
exclusions: false
customEvents: false
# sites:
# rootNodeName:
Expand Down
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ If you have a single site setup, you can adjust the configuration under the key
| `host` | `null` | If you have set a [custom domain], you can set it here. Example: `stats.jonnitto.ch` |
| `outboundLinks` | `false` | If you want the enable [outbound link click tracking], set this to `true` |
| `hashBasedRouting` | `false` | If you want the enable [Hash-based routing], set this to `true` |
| `exclusions` | `false` | If you want to [exclude specific pages] from the analytics, you can set an array with strings or a string. If you want to load just the [exclusion variant], set this to `true` |
| `customEvents` | `false` | If you want to set [custom events] in your javascript, set this to `true` or a string. If set to a string, this whole string gets included on every document. If you set custom events via Fusion or the [Carbon.Plausible:Mixin.CustomEvent] mixin, you don't have to set it to `true`. The snippet gets activated automatically if needed. The inline javascript get's minified with [JShrink] |

### Multi-site setup
Expand All @@ -89,9 +90,15 @@ Carbon:
mysecondsite:
domain: domain.org
hashBasedRouting: true
exclusions: "/blog4, /rule/*, /how-to-*, /*/admin"
mythirdsite:
domain: domain.net
customEvent: "plausible('Download', {props: {method: 'HTTP'}})"
exclusions:
- /blog4
- /rule/*
- /how-to-*
- /*/admin
```
The key of the site (e.g. `myfirstsite`) is the root node name found under Administration » Sites Management.
Expand All @@ -116,8 +123,8 @@ prototype(Vendor.Site:Document.NotFound) < prototype(Neos.Neos:Page) {
[fork]: https://github.com/CarbonPackages/Carbon.Plausible/fork
[stargazers]: https://github.com/CarbonPackages/Carbon.Plausible/stargazers
[subscription]: https://github.com/CarbonPackages/Carbon.Plausible/subscription
[screenshot of backend module]: https://user-images.githubusercontent.com/4510166/105641464-66e66000-5e84-11eb-86bb-5cc3b9d1e563.png
[error in the backend module]: https://user-images.githubusercontent.com/4510166/105641443-4f0edc00-5e84-11eb-8c97-085d8157fc53.png
[screenshot of backend module]: https://user-images.githubusercontent.com/4510166/105641544-c5abd980-5e84-11eb-8515-80ae5bda9000.png
[error in the backend module]: https://user-images.githubusercontent.com/4510166/105641545-c80e3380-5e84-11eb-8fda-31a080e990e2.png
[set cookie in the inspector]: https://user-images.githubusercontent.com/4510166/105755892-3669f900-5f4c-11eb-96ef-4a6db137a936.gif
[set options in the inspector]: https://user-images.githubusercontent.com/4510166/105755934-41248e00-5f4c-11eb-87dc-e4a4434943b0.gif
[neos]: https://www.neos.io
Expand All @@ -131,6 +138,8 @@ prototype(Vendor.Site:Document.NotFound) < prototype(Neos.Neos:Page) {
[custom domain]: https://plausible.io/docs/custom-domain
[outbound link click tracking]: https://plausible.io/docs/outbound-link-click-tracking
[hash-based routing]: https://plausible.io/docs/hash-based-routing
[exclude specific pages]: https://plausible.io/docs/excluding-pages
[exclusion variant]: https://plausible.io/docs/excluding
[carbon.plausible:component.trackingcode]: Resources/Private/Fusion/Component/TrackingCode.fusion
[neos.neos:page]: Resources/Private/Fusion/Override/Page.fusion
[jshrink]: https://github.com/tedious/JShrink
4 changes: 3 additions & 1 deletion Resources/Private/Fusion/Component/Src.fusion
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ prototype(Carbon.Plausible:Component.Src) < prototype(Neos.Fusion:Component) {
host.@process.fallback = ${value || 'plausible.io'}
outboundLinks = null
hashBasedRouting = null
exclusions = null

renderer = Neos.Fusion:Join {
protocol = 'https://'
host = ${props.host}
jsFolder = '/js/'
filename = ${props.host != 'plausible.io' ? 'index' : 'plausible'}
outboundLinks = ${props.outboundLinks ? '.outbound-links' : ''}
hashBasedRouting = ${props.hashBasedRouting ? '.hash' : ''}
exclusions = ${props.exclusions ? '.exclusions' : ''}
outboundLinks = ${props.outboundLinks ? '.outbound-links' : ''}
fileextension = '.js'
}
}
8 changes: 8 additions & 0 deletions Resources/Private/Fusion/Component/TrackingCode.fusion
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ prototype(Carbon.Plausible:Component.TrackingCode) < prototype(Neos.Fusion:Compo
domain = ${this.siteSettings.domain || this.defaultSettings.domain}
outboundLinks = ${Type.isBoolean(this.siteSettings.outboundLinks) ? this.siteSettings.outboundLinks : this.defaultSettings.outboundLinks}
hashBasedRouting = ${Type.isBoolean(this.siteSettings.hashBasedRouting) ? this.siteSettings.hashBasedRouting : this.defaultSettings.hashBasedRouting}
exclusions = ${this.siteSettings.exclusions || Type.isBoolean(this.siteSettings.exclusions) ? this.siteSettings.exclusions : this.defaultSettings.exclusions}
customEvents = ${this.siteSettings.customEvents || Type.isBoolean(this.siteSettings.customEvents) ? this.siteSettings.customEvents : this.defaultSettings.customEvents}

async = true
Expand All @@ -34,6 +35,12 @@ prototype(Carbon.Plausible:Component.TrackingCode) < prototype(Neos.Fusion:Compo
@if.shouldCheck = ${props.checkIfDomainIsTheSameAsRequest}
}

dataExclude = ${Type.isString(props.exclusions) ? props.exclusions : Array.join(props.exclusions, ',')}
dataExclude.@if {
exclusionIsSet = ${props.exclusions}
isStringOrArray = ${Type.isString(props.exclusions) || (Type.isArray(props.exclusions) && Array.length(props.exclusions))}
}

inlineJavascript = Neos.Fusion:DataStructure {
plausibleVariable = 'window.plausible = window.plausible || function() { (window.plausible.q = window.plausible.q || []).push(arguments) }'
eventFromNode = ${'plausible("' + props.eventName + '"' + (props.eventJSON ? ',' + props.eventJSON : '') + ')'}
Expand All @@ -53,6 +60,7 @@ prototype(Carbon.Plausible:Component.TrackingCode) < prototype(Neos.Fusion:Compo
async={props.async}
defer={props.defer}
data-domain={props.domain}
data-exclude={props.dataExclude}
>
<Carbon.Plausible:Component.Src @path='attributes.src' {...props} />
</script>
Expand Down
1 change: 1 addition & 0 deletions Resources/Private/Modules/Component/TableRow.fusion
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ prototype(Carbon.Plausible:Component.TableRow) < prototype(Neos.Fusion:Component
fallback = null

// Internal
value.@process.convertExclusionsArray = ${this.key == 'exclusions' && Type.isArray(value) ? Array.join(value, ',') : value}
isDomain = ${this.key == 'domain'}
domainValue = ${this.value || this.fallback}
hasString = ${this.value && Type.isString(this.value)}
Expand Down
2 changes: 1 addition & 1 deletion Resources/Private/Modules/Views/Index.fusion
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Carbon.Plausible.PlausibleController {
requestMainDomain = Carbon.Plausible:Component.RequestMainDomain
disableBecauseOfCookie = ${!!request.httpRequest.cookieParams.disabledPlausible}

table = ${['domain', 'host', 'outboundLinks', 'hashBasedRouting', 'customEvents']}
table = ${['domain', 'host', 'outboundLinks', 'hashBasedRouting', 'exclusions', 'customEvents']}

renderer = afx`
<h1>
Expand Down

0 comments on commit 58315cb

Please sign in to comment.