template <class T>

class Analytics

Defined at line 69 of file ../../src/lib/analytics/cpp/core_dev_tools/analytics.h

This class uses template following the pattern of CRTP

(See https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern).

We use CRTP instead of the more common dynamic polymorphism via inheritance, in order to

provide a simple, static interface for analytics, such that sending an event just looks like a

one-line command without creating an object first. We choose static interface here because the

action of sending analytics itself is rather static, without interacting with any internal

status that changes from instance to instance.

To use this class, one must inherit this class and specify required constants like below:

class ToolAnalytics : public Analytics

<ToolAnalytics

> {

public:

// ......

private:

friend class Analytics

<ToolAnalytics

>;

static constexpr char kToolName[] = "tool";

static constexpr char kToolVersion[] = "1.0";

static constexpr int64_t kQuitTimeoutMs = 500; // wait for at most 500ms before quitting

static constexpr char kMeasurementId[] = "G-XXXXXXXXXX";

static constexpr char kMeasurementKey[] = "YYYYYYYYYYYYYY";

static constexpr char kEnableArgs[] = "--analytics=enable";

static constexpr char kDisableArgs[] = "--analytics=disable";

static constexpr char kStatusArgs[] = "--show-analytics";

}

One also needs to (if not already) add the following lines to the main() function before any

threads are spawned and any use of Curl or Analytics:

debug_ipc::Curl::GlobalInit();

auto deferred_cleanup_curl = fit::defer(debug_ipc::Curl::GlobalCleanup);

auto deferred_cleanup_analytics = fit::defer(Analytics::CleanUp);

and include related headers, e.g.

<lib

/fit/defer.h> and "src/developer/debug/zxdb/common/curl.h".

The derived class can also define their own functions for sending analytics. For example

// The definition of a static public function in ToolAnalytics

void ToolAnalytics::IfEnabledSendExitEvent() {

if(

<runtime

analytics enabled>) {

SendGoogleAnalyticsHit(

<

...>);

}

}

Protected Members

static bool enabled_runtime_

Public Methods

void InitBotAware (AnalyticsOption analytics_option, bool enable_on_bots)

Defined at line 71 of file ../../src/lib/analytics/cpp/core_dev_tools/analytics.h

void PersistentEnable ()

Defined at line 95 of file ../../src/lib/analytics/cpp/core_dev_tools/analytics.h

void PersistentDisable ()

Defined at line 105 of file ../../src/lib/analytics/cpp/core_dev_tools/analytics.h

void ShowAnalytics ()

Show the persistent analytics status and the what is collected

Defined at line 116 of file ../../src/lib/analytics/cpp/core_dev_tools/analytics.h

void IfEnabledSendInvokeEvent ()

Defined at line 123 of file ../../src/lib/analytics/cpp/core_dev_tools/analytics.h

void IfEnabledSendGa4Event (std::unique_ptr<google_analytics_4::Event> event)

Defined at line 129 of file ../../src/lib/analytics/cpp/core_dev_tools/analytics.h

void IfEnabledSendGa4Events (std::vector<std::unique_ptr<google_analytics_4::Event>> events)

Defined at line 135 of file ../../src/lib/analytics/cpp/core_dev_tools/analytics.h

void IfEnabledAddGa4EventToDefaultBatch (std::unique_ptr<google_analytics_4::Event> event)

Defined at line 142 of file ../../src/lib/analytics/cpp/core_dev_tools/analytics.h

void IfEnabledSendDefaultBatch ()

Defined at line 148 of file ../../src/lib/analytics/cpp/core_dev_tools/analytics.h

void CleanUp ()

Defined at line 154 of file ../../src/lib/analytics/cpp/core_dev_tools/analytics.h

void InitTestingClient (std::function<void (const std::string &)> sender)

For tests only. Do not use with other Init* functions.

With this init, data will not be sent to Google Analytics. But instead the

sender function will be called with the POST body (passed as `const

std::string

&

`), which is the JSON representation of a Measurement object.

Defined at line 164 of file ../../src/lib/analytics/cpp/core_dev_tools/analytics.h

Protected Methods

void SendGa4Event (std::unique_ptr<google_analytics_4::Event> event)

Defined at line 170 of file ../../src/lib/analytics/cpp/core_dev_tools/analytics.h

bool CanSend ()

Defined at line 179 of file ../../src/lib/analytics/cpp/core_dev_tools/analytics.h

bool ClientIsCleanedUp ()

Defined at line 192 of file ../../src/lib/analytics/cpp/core_dev_tools/analytics.h

void SetRuntimeAnalyticsStatus (AnalyticsStatus status)

Defined at line 194 of file ../../src/lib/analytics/cpp/core_dev_tools/analytics.h

bool IsEnabled ()

Defined at line 198 of file ../../src/lib/analytics/cpp/core_dev_tools/analytics.h