-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTrackingCode.fusion
93 lines (76 loc) · 5.26 KB
/
TrackingCode.fusion
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
prototype(Carbon.Plausible:Component.TrackingCode) < prototype(Neos.Fusion:Component) {
enable = ${Configuration.setting('Carbon.Plausible.enable')}
doNotTrack = ${q(node).is('[instanceof Carbon.Plausible:Mixin.DoNotTrack]') && q(node).property('plausibleDoNotTrack')}
hasCustomEventMixin = ${q(node).is('[instanceof Carbon.Plausible:Mixin.CustomEvent]')}
eventName = ${this.hasCustomEventMixin ? q(node).property('plausibleCustomEventName') : null}
eventJSON = ${this.eventName ? String.trim(q(node).property('plausibleCustomEventJSON')) : null}
defaultSettings = ${Configuration.setting('Carbon.Plausible.default')}
siteName = ${site.name}
siteSettings = ${Configuration.setting('Carbon.Plausible.sites')}
siteSettings.@process.isDefined = ${this.siteName && Type.isArray(value) && Type.isArray(value[this.siteName]) ? value[this.siteName] : this.defaultSettings}
domain = ${Carbon.Plausible.getValue(this.defaultSettings, this.siteSettings, 'domain', site)}
reverseProxy = ${Carbon.Plausible.getBooleanValue(this.defaultSettings, this.siteSettings, 'reverseProxy')}
customEvents = ${Carbon.Plausible.getValue(this.defaultSettings, this.siteSettings, 'customEvents')}
dataAnalyticsTracking = ${Carbon.Plausible.getBooleanValue(this.defaultSettings, this.siteSettings, 'dataAnalyticsTracking')}
hashBasedRouting = ${Carbon.Plausible.getBooleanValue(this.defaultSettings, this.siteSettings, 'hashBasedRouting')}
outboundLinks = ${Carbon.Plausible.getBooleanValue(this.defaultSettings, this.siteSettings, 'outboundLinks', site)}
fileDownloads = ${Carbon.Plausible.getValue(this.defaultSettings, this.siteSettings, 'fileDownloads', site)}
taggedEvents = ${Carbon.Plausible.getBooleanValue(this.defaultSettings, this.siteSettings, 'taggedEvents')}
revenue = ${Carbon.Plausible.getBooleanValue(this.defaultSettings, this.siteSettings, 'revenue')}
compat = ${Carbon.Plausible.getValue(this.defaultSettings, this.siteSettings, 'compat')}
local = ${Carbon.Plausible.getValue(this.defaultSettings, this.siteSettings, 'local')}
pageviewProps = ${Carbon.Plausible.getValue(this.defaultSettings, this.siteSettings, 'pageviewProps')}
manual = ${this.siteSettings.manual || Type.isBoolean(this.siteSettings.manual) ? this.siteSettings.manual : this.defaultSettings.manual}
customEvents = ${this.siteSettings.customEvents || Type.isBoolean(this.siteSettings.customEvents) ? this.siteSettings.customEvents : this.defaultSettings.customEvents}
dataAnalyticsTracking = ${this.siteSettings.dataAnalyticsTracking || this.defaultSettings.dataAnalyticsTracking}
async = false
defer = true
checkIfDomainIsTheSameAsRequest = true
renderPlausibleScriptTag = ${this.enable && !this.doNotTrack && this.domain && !node.context.inBackend && (this.checkIfDomainIsTheSameAsRequest ? Carbon.Plausible.checkDomain(request.httpRequest, this.domain) : true)}
renderInlineScriptTag = ${this.renderPlausibleScriptTag}
@if.renderTags = ${this.renderPlausibleScriptTag || this.renderInlineScriptTag}
renderer = Neos.Fusion:Component {
@apply.props = ${props}
fileTypes = ${Type.isString(props.fileDownloads) ? props.fileDownloads : Array.join(props.fileDownloads, ',')}
fileTypes.@if {
exclusionIsSet = ${props.fileDownloads}
isStringOrArray = ${Type.isString(props.fileDownloads) || Carbon.Array.length(props.fileDownloads)}
}
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 : '') + ')'}
eventFromNode.@if.hasEventName = ${props.eventName}
customEvents = ${Type.isString(props.customEvents) ? props.customEvents : null}
@if.set = ${props.renderInlineScriptTag && (props.customEvents || props.eventName || props.dataAnalyticsTracking)}
@process.filter = ${Array.join(Array.filter(value, line => !!line), ';')}
}
plausibleSrc = Carbon.Plausible:Component.Src {
@apply.props = ${props}
}
dataAnalyticsTrackingSrc = Neos.Fusion:ResourceUri {
@if.set = ${props.renderInlineScriptTag && props.dataAnalyticsTracking}
path = 'resource://Carbon.Plausible/Public/Data.js'
}
renderer = afx`
<script
@if.set={props.renderPlausibleScriptTag && props.domain}
id={props.compat ? 'plausible' : null}
data-domain={props.domain}
data-api={props.reverseProxy ? '/~plausible' : null}
{...Carbon.Plausible.pageviewProps(props.pageviewProps)}
file-types={props.fileTypes}
src={props.plausibleSrc}
async={props.async}
defer={props.defer}
></script>
<script @if.set={props.inlineJavascript}>
{Carbon.String.minifyJS(props.inlineJavascript)}
</script>
<script
@if.set={props.dataAnalyticsTrackingSrc}
src={props.dataAnalyticsTrackingSrc}
defer
></script>
`
}
}