The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

117 lines
4.0KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 6 End-User License
  8. Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
  9. End User License Agreement: www.juce.com/juce-6-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. //==============================================================================
  21. /**
  22. A singleton class to manage analytics data.
  23. Use an Analytics object to manage sending analytics data to one or more
  24. AnalyticsDestinations.
  25. @see AnalyticsDestination, ThreadedAnalyticsDestination,
  26. AnalyticsDestination::AnalyticsEvent
  27. @tags{Analytics}
  28. */
  29. class JUCE_API Analytics : public DeletedAtShutdown
  30. {
  31. public:
  32. //==============================================================================
  33. /** Adds an AnalyticsDestination to the list of AnalyticsDestinations
  34. managed by this Analytics object.
  35. The Analytics class will take ownership of the AnalyticsDestination
  36. passed to this function.
  37. @param destination the AnalyticsDestination to manage
  38. */
  39. void addDestination (AnalyticsDestination* destination);
  40. /** Returns the array of AnalyticsDestinations managed by this class.
  41. If you have added any subclasses of ThreadedAnalyticsDestination to
  42. this class then you can remove them from this list to force them to
  43. flush any pending events.
  44. */
  45. OwnedArray<AnalyticsDestination>& getDestinations();
  46. /** Sets a user ID that will be added to all AnalyticsEvents sent to
  47. AnalyticsDestinations.
  48. @param newUserId the userId to add to AnalyticsEvents
  49. */
  50. void setUserId (String newUserId);
  51. /** Sets some user properties that will be added to all AnalyticsEvents sent
  52. to AnalyticsDestinations.
  53. @param properties the userProperties to add to AnalyticsEvents
  54. */
  55. void setUserProperties (StringPairArray properties);
  56. /** Sends an AnalyticsEvent to all AnalyticsDestinations.
  57. The AnalyticsEvent will be timestamped, and will have the userId and
  58. userProperties populated by values previously set by calls to
  59. setUserId and setUserProperties. The name, parameters and type will be
  60. populated by the arguments supplied to this function.
  61. @param eventName the event name
  62. @param parameters the event parameters
  63. @param eventType (optional) an integer to indicate the event
  64. type, which will be set to 0 if not supplied.
  65. */
  66. void logEvent (const String& eventName, const StringPairArray& parameters, int eventType = 0);
  67. /** Suspends analytics submissions to AnalyticsDestinations.
  68. @param shouldBeSuspended if event submission should be suspended
  69. */
  70. void setSuspended (bool shouldBeSuspended);
  71. #ifndef DOXYGEN
  72. JUCE_DECLARE_SINGLETON (Analytics, false)
  73. #endif
  74. private:
  75. //==============================================================================
  76. Analytics() = default;
  77. ~Analytics() override { clearSingletonInstance(); }
  78. String userId;
  79. StringPairArray userProperties;
  80. bool isSuspended = false;
  81. OwnedArray<AnalyticsDestination> destinations;
  82. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Analytics)
  83. };
  84. } // namespace juce