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.

110 lines
3.8KB

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