Metrics.lua 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. ----------------------------------------------------------------------------------------------------
  2. --
  3. -- Copyright (c) Contributors to the Open 3D Engine Project.
  4. -- For complete copyright and license terms please see the LICENSE at the root of this distribution.
  5. --
  6. -- SPDX-License-Identifier: Apache-2.0 OR MIT
  7. --
  8. --
  9. --
  10. ----------------------------------------------------------------------------------------------------
  11. local metrics = {
  12. }
  13. function metrics:OnActivate()
  14. self.tickTime = 0
  15. self.numSubmittedMetricsEvents = 0
  16. self.tickBusHandler = TickBus.Connect(self,self.entityId)
  17. self.metricsNotificationHandler = AWSMetricsNotificationBus.Connect(self, self.entityId)
  18. LyShineLua.ShowMouseCursor(true)
  19. end
  20. function metrics:OnSendMetricsSuccess(requestId)
  21. Debug.Log("Metrics is sent successfully.")
  22. end
  23. function metrics:OnSendMetricsFailure(requestId, errorMessage)
  24. Debug.Log("Failed to send metrics.")
  25. end
  26. function metrics:OnDeactivate()
  27. self.tickBusHandler:Disconnect()
  28. self.metricsNotificationHandler:Disconnect()
  29. end
  30. function metrics:OnTick(deltaTime, timePoint)
  31. self.tickTime = self.tickTime + deltaTime
  32. if self.tickTime > 5.0 then
  33. defaultAttribute = AWSMetrics_MetricsAttribute()
  34. defaultAttribute:SetName("event_name")
  35. defaultAttribute:SetStrValue("login")
  36. customAttribute = AWSMetrics_MetricsAttribute()
  37. customAttribute:SetName("custom_attribute")
  38. customAttribute:SetStrValue("value")
  39. attributeList = AWSMetrics_AttributesSubmissionList()
  40. attributeList.attributes:push_back(defaultAttribute)
  41. attributeList.attributes:push_back(customAttribute)
  42. if self.numSubmittedMetricsEvents % 2 == 0 then
  43. if AWSMetricsRequestBus.Broadcast.SubmitMetrics(attributeList.attributes, 0, "lua", false) then
  44. Debug.Log("Submitted metrics without buffer.")
  45. AWSMetricsRequestBus.Broadcast.FlushMetrics()
  46. Debug.Log("Flushed the buffered metrics.")
  47. else
  48. Debug.Log("Failed to Submit metrics without buffer.")
  49. end
  50. else
  51. if AWSMetricsRequestBus.Broadcast.SubmitMetrics(attributeList.attributes, 0, "lua", true) then
  52. Debug.Log("Submitted metrics with buffer.")
  53. else
  54. Debug.Log("Failed to Submit metrics with buffer.")
  55. end
  56. end
  57. self.numSubmittedMetricsEvents = self.numSubmittedMetricsEvents + 1
  58. self.tickTime = 0
  59. end
  60. end
  61. return metrics