forked from Haleth/Aurora
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathanalytics.lua
More file actions
120 lines (99 loc) · 3.61 KB
/
analytics.lua
File metadata and controls
120 lines (99 loc) · 3.61 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
local _, private = ...
-- [[ Lua Globals ]]
-- luacheck: globals pairs type
-- Analytics Integration Module
-- Handles WagoAnalytics integration, user consent, privacy controls, and event tracking
local Analytics = {}
private.Analytics = Analytics
-- Analytics state
Analytics.enabled = false
Analytics.wago = nil
Analytics.consentGiven = nil
-- Initialize analytics system
-- @param wago table The WagoAnalytics instance
-- @param config table The configuration object
function Analytics.initialize(wago, config)
Analytics.wago = wago
-- Check if user has given consent (hasAnalytics setting)
Analytics.consentGiven = config.hasAnalytics
Analytics.enabled = Analytics.consentGiven and wago ~= nil
if Analytics.enabled then
private.debug("Analytics", "Initialized with user consent")
else
private.debug("Analytics", "Disabled - consent:", Analytics.consentGiven, "wago:", wago ~= nil)
end
end
-- Track a configuration change event
-- @param key string The configuration key that changed
-- @param value any The new value
function Analytics.trackConfigChange(key, value)
if not Analytics.enabled or not Analytics.wago then
return
end
-- Skip tracking for privacy-sensitive settings
if key == "acknowledgedSplashScreen" or key == "hasAnalytics" then
return
end
-- Track based on value type
if key == "customHighlight" then
-- Track custom highlight enable/disable
if type(value) == "table" and value.enabled ~= nil then
Analytics.wago:Switch(key, value.enabled)
end
elseif key == "alpha" then
-- Track numeric values as counters
if type(value) == "number" then
Analytics.wago:SetCounter(key, value)
end
elseif type(value) == "boolean" then
-- Track boolean toggles
Analytics.wago:Switch(key, value)
end
private.debug("Analytics", "Tracked config change:", key, "=", value)
end
-- Enable analytics with user consent
-- @param config table The configuration object
function Analytics.enable(config)
if not Analytics.wago then
private.debug("Analytics", "Cannot enable - WagoAnalytics not available")
return false
end
config.hasAnalytics = true
Analytics.consentGiven = true
Analytics.enabled = true
private.debug("Analytics", "Enabled with user consent")
return true
end
-- Disable analytics and revoke consent
-- @param config table The configuration object
function Analytics.disable(config)
config.hasAnalytics = false
Analytics.consentGiven = false
Analytics.enabled = false
private.debug("Analytics", "Disabled by user")
return true
end
-- Check if analytics is available
-- @return boolean Whether WagoAnalytics is available
function Analytics.isAvailable()
return Analytics.wago ~= nil
end
-- Check if user has given consent
-- @return boolean Whether user has consented to analytics
function Analytics.hasConsent()
return Analytics.consentGiven == true
end
-- Track initial configuration state
-- @param config table The configuration object
function Analytics.trackInitialState(config)
if not Analytics.enabled or not Analytics.wago then
return
end
-- Track all non-sensitive settings
for key, value in pairs(config) do
if key ~= "acknowledgedSplashScreen" and key ~= "hasAnalytics" and key ~= "customClassColors" then
Analytics.trackConfigChange(key, value)
end
end
private.debug("Analytics", "Tracked initial configuration state")
end