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
|
# File 'lib/al_analytics.rb', line 5
def render(context)
site = context.registers[:site]
return "" unless site
output = []
cookie_attrs = cookie_consent_attrs(site)
google_id = analytics_value(site, "google_analytics", "google")
if enabled?(site, "enable_google_analytics", google_id)
output << <<~HTML
<!-- Google Analytics -->
<script#{cookie_attrs} async src="https://www.googletagmanager.com/gtag/js?id=#{google_id}"></script>
<script#{cookie_attrs}>
window.dataLayer = window.dataLayer || [];
function gtag() {
window.dataLayer.push(arguments);
}
gtag("js", new Date());
gtag("config", "#{google_id}");
</script>
HTML
end
cronitor_id = analytics_value(site, "cronitor_analytics", "cronitor")
if enabled?(site, "enable_cronitor_analytics", cronitor_id)
output << <<~HTML
<!-- Cronitor RUM -->
<script#{cookie_attrs} async src="https://rum.cronitor.io/script.js"></script>
<script#{cookie_attrs}>
window.cronitor =
window.cronitor ||
function () {
(window.cronitor.q = window.cronitor.q || []).push(arguments);
};
cronitor("config", { clientKey: "#{cronitor_id}" });
</script>
HTML
end
pirsch_id = analytics_value(site, "pirsch_analytics", "pirsch")
if enabled?(site, "enable_pirsch_analytics", pirsch_id)
output << <<~HTML
<script#{cookie_attrs} defer src="https://api.pirsch.io/pa.js" id="pianjs" data-code="#{pirsch_id}"></script>
HTML
end
openpanel_id = analytics_value(site, "openpanel_analytics", "openpanel")
if enabled?(site, "enable_openpanel_analytics", openpanel_id)
output << <<~HTML
<script#{cookie_attrs}>
window.op =
window.op ||
function (...args) {
(window.op.q = window.op.q || []).push(args);
};
window.op("init", {
clientId: "#{openpanel_id}",
trackScreenViews: true,
trackOutgoingLinks: true,
trackAttributes: true,
});
</script>
<script#{cookie_attrs} async defer src="https://openpanel.dev/op1.js"></script>
HTML
end
cloudflare_token = analytics_value(site, "cloudflare_analytics", "cloudflare")
if enabled?(site, "enable_cloudflare_analytics", cloudflare_token)
output << <<~HTML
<!-- Cloudflare Web Analytics -->
<script#{cookie_attrs} defer src="https://static.cloudflareinsights.com/beacon.min.js" data-cf-beacon='{"token": "#{cloudflare_token}"}'></script>
HTML
end
if flag_enabled?(site, "enable_simple_analytics")
output << <<~HTML
<script#{cookie_attrs} async src="https://scripts.simpleanalyticscdn.com/latest.js"></script>
HTML
end
output.join("\n")
end
|