TheHeckingDeveloper

AnalyticsManager

Apr 26th, 2021
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.73 KB | None | 0 0
  1. -- Services
  2. local ServerStorage = game:GetService("ServerStorage")
  3.  
  4. -- Folders
  5. local configurations = ServerStorage:WaitForChild("Configurations")
  6. local classes = ServerStorage:WaitForChild("Classes")
  7.  
  8. -- Classes
  9. local DSInterface = require(classes:WaitForChild("DSInterface"))
  10.  
  11. -- DSInterfaces
  12. local analyticsInterface = DSInterface.new("GameAnalytics")
  13.  
  14. -- Function cache
  15. local osDate = os.date
  16.  
  17. -- Tables
  18. local module = {}
  19.  
  20. -- Private functions
  21. local function joinValues(...)
  22.     local str = "%g" .. string.rep(" : %g", #{...} - 1)
  23.    
  24.     return str:format(...)
  25. end
  26.  
  27. -- Functions
  28. function module:IncrementAnalytics(generalAnalytics)
  29.     local currentDate = osDate("*t")
  30.  
  31.     local currentDay = tostring(currentDate.day)
  32.     local currentMonth = currentDate.month
  33.     local currentYear = currentDate.year
  34.    
  35.     local dateKey = joinValues(currentMonth, currentYear)
  36.    
  37.     local monthData = analyticsInterface:Get(dateKey) or {}
  38.     local allTimeData = analyticsInterface:Get("AllTime")
  39.    
  40.     if monthData then
  41.         local activeUsers = generalAnalytics.ActiveUsers
  42.  
  43.         local dayUsers = activeUsers.Day
  44.         local monthUsers = activeUsers.Month
  45.        
  46.         local DAU = monthData.DAU or {}
  47.         local TodayDAU = DAU[currentDay]
  48.        
  49.         print(monthData)
  50.  
  51.         if not TodayDAU then
  52.             print("Assigning")
  53.            
  54.             DAU[currentDay] = dayUsers
  55.         else
  56.             print("Adding")
  57.            
  58.             DAU[currentDay] += dayUsers
  59.         end
  60.  
  61.         monthData.DAU = DAU
  62.        
  63.         monthData.MAU = monthData.MAU or 0
  64.         monthData.MAU += monthUsers
  65.        
  66.         print(monthData)
  67.        
  68.         analyticsInterface:Set(dateKey, monthData)
  69.     end
  70.    
  71.     if allTimeData then
  72.         allTimeData.UniqueUsers += generalAnalytics.UniqueUsers
  73.        
  74.         print(allTimeData)
  75.        
  76.         analyticsInterface:Set("AllTime", allTimeData)
  77.     end
  78. end
  79.  
  80. return module
Advertisement
Add Comment
Please, Sign In to add comment