al_analytics 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (6) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +6 -0
  3. data/LICENSE +20 -0
  4. data/README.md +67 -0
  5. data/lib/al_analytics.rb +105 -0
  6. metadata +125 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 288bcac5557544e999beda5b82eb92d488b595e2543fb2ced541552092129cd2
4
+ data.tar.gz: 89e1a046ade9be53cdf305a5090f8ad88d90b0312797937c1058b5dfe5b3706a
5
+ SHA512:
6
+ metadata.gz: def9278e280992b61a33a381e20efa550a657b9d309c8e89e8d3fe0e85a6fa9446d3c4684308daaaffd59e8aabdc0080a9b6a129cb019500201892555cf724d4
7
+ data.tar.gz: c929f9d4e0c0fce8e79cfdf968b40bd428c05dd38c5cfe5ca893e31cb12455f7031865a3139c3e983a6f370079ddcaff6b1b10e3e220ae266e21eb1caa6b6cf5
data/CHANGELOG.md ADDED
@@ -0,0 +1,6 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0 - 2026-02-07
4
+ - Initial gem release.
5
+ - Added support for modern al-folio analytics config keys with legacy `analytics:` fallback.
6
+ - Added optional cookie-consent script attributes and provider enable flags.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Maruan Al-Shedivat.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # Al-Analytics
2
+
3
+ A Jekyll plugin that provides integrations with various analytics services for al-folio sites.
4
+
5
+ ## Supported Analytics Services
6
+
7
+ - Google Analytics
8
+ - Cronitor Analytics
9
+ - Pirsch Analytics
10
+ - OpenPanel Analytics
11
+
12
+ ## Installation
13
+
14
+ Add this line to your Jekyll site's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'al_analytics'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ ```bash
23
+ $ bundle install
24
+ ```
25
+
26
+ ## Usage
27
+
28
+ 1. Add the plugin to your site's `_config.yml`:
29
+
30
+ ```yaml
31
+ plugins:
32
+ - al_analytics
33
+ ```
34
+
35
+ 2. Configure your analytics services in `_config.yml`:
36
+
37
+ ```yaml
38
+ enable_cookie_consent: false
39
+
40
+ enable_google_analytics: true
41
+ google_analytics: "G-XXXXXXXXXX"
42
+
43
+ enable_cronitor_analytics: false
44
+ cronitor_analytics: "XXXXXXXXX"
45
+
46
+ enable_pirsch_analytics: false
47
+ pirsch_analytics: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
48
+
49
+ enable_openpanel_analytics: false
50
+ openpanel_analytics: "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
51
+ ```
52
+
53
+ The plugin also supports the legacy `analytics:` hash used by earlier releases.
54
+
55
+ 3. Add the analytics tag to your layout file (e.g., `_layouts/default.html`):
56
+
57
+ ```liquid
58
+ {% al_analytics_scripts %}
59
+ ```
60
+
61
+ ## Development
62
+
63
+ After checking out the repo, run `bundle install` to install dependencies.
64
+
65
+ ## Contributing
66
+
67
+ Bug reports and pull requests are welcome on GitHub.
@@ -0,0 +1,105 @@
1
+ require "jekyll"
2
+
3
+ module AlAnalytics
4
+ class AnalyticsTag < Liquid::Tag
5
+ def render(context)
6
+ site = context.registers[:site]
7
+ return "" unless site
8
+
9
+ output = []
10
+ cookie_attrs = cookie_consent_attrs(site)
11
+
12
+ google_id = analytics_value(site, "google_analytics", "google")
13
+ if enabled?(site, "enable_google_analytics", google_id)
14
+ output << <<~HTML
15
+ <!-- Google Analytics -->
16
+ <script#{cookie_attrs} async src="https://www.googletagmanager.com/gtag/js?id=#{google_id}"></script>
17
+ <script#{cookie_attrs}>
18
+ window.dataLayer = window.dataLayer || [];
19
+ function gtag() {
20
+ window.dataLayer.push(arguments);
21
+ }
22
+ gtag("js", new Date());
23
+ gtag("config", "#{google_id}");
24
+ </script>
25
+ HTML
26
+ end
27
+
28
+ cronitor_id = analytics_value(site, "cronitor_analytics", "cronitor")
29
+ if enabled?(site, "enable_cronitor_analytics", cronitor_id)
30
+ output << <<~HTML
31
+ <!-- Cronitor RUM -->
32
+ <script#{cookie_attrs} async src="https://rum.cronitor.io/script.js"></script>
33
+ <script#{cookie_attrs}>
34
+ window.cronitor =
35
+ window.cronitor ||
36
+ function () {
37
+ (window.cronitor.q = window.cronitor.q || []).push(arguments);
38
+ };
39
+ cronitor("config", { clientKey: "#{cronitor_id}" });
40
+ </script>
41
+ HTML
42
+ end
43
+
44
+ pirsch_id = analytics_value(site, "pirsch_analytics", "pirsch")
45
+ if enabled?(site, "enable_pirsch_analytics", pirsch_id)
46
+ output << <<~HTML
47
+ <script#{cookie_attrs} defer src="https://api.pirsch.io/pa.js" id="pianjs" data-code="#{pirsch_id}"></script>
48
+ HTML
49
+ end
50
+
51
+ openpanel_id = analytics_value(site, "openpanel_analytics", "openpanel")
52
+ if enabled?(site, "enable_openpanel_analytics", openpanel_id)
53
+ output << <<~HTML
54
+ <script#{cookie_attrs}>
55
+ window.op =
56
+ window.op ||
57
+ function (...args) {
58
+ (window.op.q = window.op.q || []).push(args);
59
+ };
60
+ window.op("init", {
61
+ clientId: "#{openpanel_id}",
62
+ trackScreenViews: true,
63
+ trackOutgoingLinks: true,
64
+ trackAttributes: true,
65
+ });
66
+ </script>
67
+ <script#{cookie_attrs} async defer src="https://openpanel.dev/op1.js"></script>
68
+ HTML
69
+ end
70
+
71
+ output.join("\n")
72
+ end
73
+
74
+ private
75
+
76
+ def cookie_consent_attrs(site)
77
+ site.config["enable_cookie_consent"] ? ' type="text/plain" data-category="analytics"' : ""
78
+ end
79
+
80
+ def analytics_value(site, key, legacy_key)
81
+ value = site.config[key]
82
+ return value unless blank?(value)
83
+
84
+ legacy_config = site.config["analytics"]
85
+ return nil unless legacy_config.is_a?(Hash)
86
+
87
+ legacy_config[legacy_key]
88
+ end
89
+
90
+ def enabled?(site, flag_key, value)
91
+ return false if blank?(value)
92
+
93
+ flag = site.config[flag_key]
94
+ return true if flag.nil?
95
+
96
+ !!flag
97
+ end
98
+
99
+ def blank?(value)
100
+ value.nil? || value.to_s.strip.empty?
101
+ end
102
+ end
103
+ end
104
+
105
+ Liquid::Template.register_tag("al_analytics_scripts", AlAnalytics::AnalyticsTag)
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: al_analytics
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - al-org
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2026-02-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jekyll
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.9'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '3.9'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: liquid
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '4.0'
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '6.0'
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '4.0'
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '6.0'
53
+ - !ruby/object:Gem::Dependency
54
+ name: bundler
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '2.0'
60
+ - - "<"
61
+ - !ruby/object:Gem::Version
62
+ version: '3.0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '2.0'
70
+ - - "<"
71
+ - !ruby/object:Gem::Version
72
+ version: '3.0'
73
+ - !ruby/object:Gem::Dependency
74
+ name: rake
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: '13.0'
80
+ type: :development
81
+ prerelease: false
82
+ version_requirements: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - "~>"
85
+ - !ruby/object:Gem::Version
86
+ version: '13.0'
87
+ description: Jekyll plugin extracted from al-folio that renders Google Analytics,
88
+ Cronitor RUM, Pirsch, and OpenPanel scripts with optional cookie-consent attributes.
89
+ email:
90
+ - dev@al-org.dev
91
+ executables: []
92
+ extensions: []
93
+ extra_rdoc_files: []
94
+ files:
95
+ - CHANGELOG.md
96
+ - LICENSE
97
+ - README.md
98
+ - lib/al_analytics.rb
99
+ homepage: https://github.com/al-org-dev/al-analytics
100
+ licenses:
101
+ - MIT
102
+ metadata:
103
+ allowed_push_host: https://rubygems.org
104
+ homepage_uri: https://github.com/al-org-dev/al-analytics
105
+ source_code_uri: https://github.com/al-org-dev/al-analytics
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '2.7'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubygems_version: 3.0.3.1
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: Analytics integration tags for al-folio Jekyll sites
125
+ test_files: []