-
Notifications
You must be signed in to change notification settings - Fork 136
Expand file tree
/
Copy pathanalytics_desktop.cc
More file actions
695 lines (620 loc) · 25.1 KB
/
analytics_desktop.cc
File metadata and controls
695 lines (620 loc) · 25.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <future>
#include <map>
#include <mutex>
#include <sstream>
#include <string>
#include <vector>
#include "analytics/src/analytics_common.h"
#include "analytics/src/analytics_desktop_dynamic.h"
#include "analytics/src/include/firebase/analytics.h"
#include "app/src/future_manager.h" // For FutureData
#include "app/src/include/firebase/app.h"
#include "app/src/include/firebase/future.h"
#include "app/src/include/firebase/variant.h"
#include "app/src/log.h"
#include "firebase/log.h"
#if defined(_WIN32)
#include <windows.h>
#include "analytics_windows.h"
#endif // defined(_WIN32)
namespace firebase {
namespace analytics {
#if defined(_WIN32)
#define ANALYTICS_DLL_FILENAME L"google_analytics.dll"
static HMODULE g_analytics_module = 0;
#endif // defined(_WIN32)
// Future data for analytics.
// This is initialized in `Initialize()` and cleaned up in `Terminate()`.
static bool g_initialized = false;
static LogCallback g_log_callback;
static std::mutex g_log_callback_mutex;
static int g_fake_instance_id = 0;
static bool g_analytics_collection_enabled = true;
static std::string g_app_id;
static std::string g_package_name;
// Initializes the Analytics desktop API.
// This function must be called before any other Analytics methods.
void Initialize(const App& app) {
g_initialized = true;
internal::RegisterTerminateOnDefaultAppDestroy();
internal::FutureData::Create();
g_fake_instance_id = 0;
#if defined(_WIN32)
if (!g_analytics_module) {
std::vector<std::string> allowed_hashes;
for (int i = 0; i < FirebaseAnalytics_KnownWindowsDllHashCount; i++) {
allowed_hashes.push_back(
std::string(FirebaseAnalytics_KnownWindowsDllHashes[i]));
}
g_analytics_module =
firebase::analytics::internal::VerifyAndLoadAnalyticsLibrary(
ANALYTICS_DLL_FILENAME, allowed_hashes);
if (g_analytics_module) {
int num_loaded =
FirebaseAnalytics_LoadDynamicFunctions(g_analytics_module);
if (num_loaded < FirebaseAnalytics_DynamicFunctionCount) {
LogWarning(
"Analytics: Failed to load functions from Google Analytics "
"module (%d out of %d loaded), reverting to stubs.",
num_loaded, FirebaseAnalytics_DynamicFunctionCount);
FirebaseAnalytics_UnloadDynamicFunctions();
FreeLibrary(g_analytics_module);
g_analytics_module = 0;
// Do not proceed with C API initialization if functions didn't load
} else {
LogInfo("Analytics: Loaded Google Analytics module.");
// Initialize Google Analytics C API
g_app_id = app.options().app_id();
g_package_name = app.options().package_name();
GoogleAnalytics_Options* c_options = GoogleAnalytics_Options_Create();
if (!c_options) {
LogError("Analytics: Failed to create GoogleAnalytics_Options.");
} else {
c_options->app_id = g_app_id.c_str();
c_options->package_name = g_package_name.c_str();
c_options->analytics_collection_enabled_at_first_launch =
g_analytics_collection_enabled;
LogInfo(
"Analytics: Initializing Google Analytics C API with App ID: %s, "
"Package Name: %s",
c_options->app_id ? c_options->app_id : "null",
c_options->package_name ? c_options->package_name : "null");
if (!GoogleAnalytics_Initialize(c_options)) {
LogError("Analytics: Failed to initialize Google Analytics C API.");
// GoogleAnalytics_Initialize destroys c_options automatically if
// created by _Create
} else {
LogInfo(
"Analytics: Google Analytics C API initialized successfully.");
}
}
}
} else {
// LogWarning for g_analytics_module load failure is handled by
// VerifyAndLoadAnalyticsLibrary
g_analytics_module = 0; // Ensure it's null if loading failed
}
}
#endif // defined(_WIN32)
}
namespace internal {
// Determine whether the analytics module is initialized.
bool IsInitialized() { return g_initialized; }
} // namespace internal
// Terminates the Analytics desktop API.
// Call this function when Analytics is no longer needed to free up resources.
void Terminate() {
#if defined(_WIN32)
if (g_analytics_module) {
// Make sure to notify the SDK that the analytics is being terminated to
// upload any pending data.
NotifyAppLifecycleChange(AppLifecycleState::kTermination);
FirebaseAnalytics_UnloadDynamicFunctions();
FreeLibrary(g_analytics_module);
g_analytics_module = 0;
}
#endif // defined(_WIN32)
internal::FutureData::Destroy();
internal::UnregisterTerminateOnDefaultAppDestroy();
g_initialized = false;
}
static void ConvertParametersToGAParams(
const Parameter* parameters, size_t number_of_parameters,
GoogleAnalytics_EventParameters* c_event_params) {
if (!parameters || number_of_parameters == 0 || !c_event_params) {
return;
}
for (size_t i = 0; i < number_of_parameters; ++i) {
const Parameter& param = parameters[i];
if (param.name == nullptr || param.name[0] == '\0') {
LogError("Analytics: Parameter name cannot be null or empty.");
continue;
}
if (param.value.is_int64()) {
GoogleAnalytics_EventParameters_InsertInt(c_event_params, param.name,
param.value.int64_value());
} else if (param.value.is_double()) {
GoogleAnalytics_EventParameters_InsertDouble(c_event_params, param.name,
param.value.double_value());
} else if (param.value.is_string()) {
GoogleAnalytics_EventParameters_InsertString(c_event_params, param.name,
param.value.string_value());
} else if (param.value.is_vector()) {
// Vector types for top-level event parameters are not supported on
// Desktop. Only specific complex types (like a map processed into an
// ItemVector) are handled.
#if defined(_WIN32)
if (g_analytics_module) {
// Only log this if we are not in stub mode.
LogError(
"Analytics: Parameter '%s' has type Vector, which is unsupported "
"for "
"event parameters on Desktop. Skipping.",
param.name);
}
#endif // defined(_WIN32)
continue; // Skip this parameter
} else if (param.value.is_map()) {
// This block handles parameters that are maps.
// Each key-value pair from the input map is converted into a distinct
// GoogleAnalytics_Item. In each such GoogleAnalytics_Item, the original
// key from the map is used directly as the property key, and the original
// value (which must be a primitive) is set as the property's value. All
// these GoogleAnalytics_Items are then bundled into a single
// GoogleAnalytics_ItemVector, which is associated with the original
// parameter's name.
const std::map<firebase::Variant, firebase::Variant>& user_map =
param.value.map();
if (user_map.empty()) {
LogWarning("Analytics: Parameter '%s' is an empty map. Skipping.",
param.name);
continue; // Skip this parameter
}
GoogleAnalytics_ItemVector* c_item_vector =
GoogleAnalytics_ItemVector_Create();
if (!c_item_vector) {
LogError(
"Analytics: Failed to create ItemVector for map parameter '%s'.",
param.name);
continue; // Skip this parameter
}
bool item_vector_populated = false;
for (const auto& entry : user_map) {
const firebase::Variant& key_variant = entry.first;
if (!key_variant.is_string()) {
LogError("Analytics: Non-string map key found. Skipping.");
continue;
}
const std::string& key_from_map = key_variant.mutable_string();
const firebase::Variant& value_from_map = entry.second;
GoogleAnalytics_Item* c_item = GoogleAnalytics_Item_Create();
if (!c_item) {
LogError(
"Analytics: Failed to create Item for key '%s' in map parameter "
"'%s'.",
key_from_map.c_str(), param.name);
continue; // Skip this key-value pair, try next one in map
}
bool successfully_set_property = false;
if (value_from_map.is_int64()) {
GoogleAnalytics_Item_InsertInt(c_item, key_from_map.c_str(),
value_from_map.int64_value());
successfully_set_property = true;
} else if (value_from_map.is_double()) {
GoogleAnalytics_Item_InsertDouble(c_item, key_from_map.c_str(),
value_from_map.double_value());
successfully_set_property = true;
} else if (value_from_map.is_string()) {
GoogleAnalytics_Item_InsertString(c_item, key_from_map.c_str(),
value_from_map.string_value());
successfully_set_property = true;
} else {
LogWarning(
"Analytics: Value for key '%s' in map parameter '%s' has an "
"unsupported Variant type. This key-value pair will be skipped.",
key_from_map.c_str(), param.name);
// successfully_set_property remains false
}
if (successfully_set_property) {
GoogleAnalytics_ItemVector_InsertItem(c_item_vector, c_item);
// c_item is now owned by c_item_vector
item_vector_populated =
true; // Mark that the vector has at least one item
} else {
// If no property was set (e.g., value type was unsupported), destroy
// the created c_item.
GoogleAnalytics_Item_Destroy(c_item);
}
}
if (item_vector_populated) {
GoogleAnalytics_EventParameters_InsertItemVector(
c_event_params, param.name, c_item_vector);
// c_item_vector is now owned by c_event_params
} else {
// If no items were successfully created and added (e.g., all values in
// map were unsupported types)
GoogleAnalytics_ItemVector_Destroy(c_item_vector);
LogWarning(
"Analytics: Map parameter '%s' resulted in an empty ItemVector; no "
"valid key-value pairs found or all values had unsupported types. "
"This map parameter was skipped.",
param.name);
}
} else {
LogWarning("Analytics: Unsupported variant type for parameter '%s'.",
param.name);
}
}
}
// Logs an event with the given name and parameters.
void LogEvent(const char* name, const Parameter* parameters,
size_t number_of_parameters) {
FIREBASE_ASSERT_RETURN_VOID(internal::IsInitialized());
if (name == nullptr || name[0] == '\0') {
LogError("Analytics: Event name cannot be null or empty.");
return;
}
GoogleAnalytics_EventParameters* c_event_params = nullptr;
if (parameters != nullptr && number_of_parameters > 0) {
c_event_params = GoogleAnalytics_EventParameters_Create();
if (!c_event_params) {
LogError(
"Analytics: Failed to create event parameters map for event '%s'.",
name);
return;
}
ConvertParametersToGAParams(parameters, number_of_parameters,
c_event_params);
}
GoogleAnalytics_LogEvent(name, c_event_params);
// GoogleAnalytics_LogEvent is expected to handle the lifecycle of
// c_event_params if non-null.
}
// log an event and the associated parameters via a vector.
void LogEvent(const char* name, const std::vector<Parameter>& parameters) {
LogEvent(name, parameters.data(), parameters.size());
}
// Sets a user property to the given value.
//
// Up to 25 user property names are supported. Once set, user property values
// persist throughout the app lifecycle and across sessions.
//
// @param[in] name The name of the user property to set. Should contain 1 to 24
// alphanumeric characters or underscores, and must start with an alphabetic
// character. The "firebase_", "google_", and "ga_" prefixes are reserved and
// should not be used for user property names. Must be UTF-8 encoded.
// @param[in] value The value of the user property. Values can be up to 36
// characters long. Setting the value to `nullptr` or an empty string will
// clear the user property. Must be UTF-8 encoded if not nullptr.
void SetUserProperty(const char* name, const char* property) {
FIREBASE_ASSERT_RETURN_VOID(internal::IsInitialized());
if (name == nullptr || name[0] == '\0') {
LogError("Analytics: User property name cannot be null or empty.");
return;
}
// The C API GoogleAnalytics_SetUserProperty allows value to be nullptr to
// remove the property. If value is an empty string, it might also be treated
// as clearing by some backends, or it might be an invalid value. The C API
// doc says: "Setting the value to `nullptr` remove the user property." For
// consistency, we pass it as is.
GoogleAnalytics_SetUserProperty(name, property);
}
// Sets the user ID property.
// This feature must be used in accordance with Google's Privacy Policy.
//
// @param[in] user_id The user ID associated with the user of this app on this
// device. The user ID must be non-empty if not nullptr, and no more than 256
// characters long, and UTF-8 encoded. Setting user_id to `nullptr` removes
// the user ID.
void SetUserId(const char* user_id) {
FIREBASE_ASSERT_RETURN_VOID(internal::IsInitialized());
// The C API GoogleAnalytics_SetUserId allows user_id to be nullptr to clear
// the user ID. The C API documentation also mentions: "The user ID must be
// non-empty and no more than 256 characters long". We'll pass nullptr as is.
// If user_id is an empty string "", this might be an issue for the underlying
// C API or backend if it expects non-empty. However, the Firebase API
// typically allows passing "" to clear some fields, or it's treated as an
// invalid value. For SetUserId, `nullptr` is the standard clear mechanism. An
// empty string might be an invalid ID. For now, we are not adding extra
// validation for empty string beyond what C API does. Consider adding a check
// for empty string if Firebase spec requires it. e.g., if (user_id != nullptr
// && user_id[0] == '\0') { /* log error */ return; }
GoogleAnalytics_SetUserId(user_id);
}
// Sets whether analytics collection is enabled for this app on this device.
// This setting is persisted across app sessions. By default it is enabled.
//
// @param[in] enabled A flag that enables or disables Analytics collection.
void SetAnalyticsCollectionEnabled(bool enabled) {
g_analytics_collection_enabled = enabled;
if (internal::IsInitialized()) {
GoogleAnalytics_SetAnalyticsCollectionEnabled(enabled);
}
}
// Clears all analytics data for this app from the device and resets the app
// instance ID.
void ResetAnalyticsData() {
FIREBASE_ASSERT_RETURN_VOID(internal::IsInitialized());
GoogleAnalytics_ResetAnalyticsData();
g_fake_instance_id++;
}
LogLevel ConvertAnalyticsLogLevelToFirebaseLogLevel(
GoogleAnalytics_LogLevel log_level) {
switch (log_level) {
case kDebug:
return kLogLevelDebug;
case kInfo:
return kLogLevelInfo;
case kWarning:
return kLogLevelWarning;
case kError:
return kLogLevelError;
default:
return kLogLevelInfo;
}
}
void GoogleAnalyticsWrapperLogCallback(int32_t log_level, const char* message) {
LogCallback callback_to_call;
{
std::lock_guard<std::mutex> lock(g_log_callback_mutex);
callback_to_call = g_log_callback;
}
if (callback_to_call) {
LogLevel firebase_log_level = ConvertAnalyticsLogLevelToFirebaseLogLevel(
static_cast<GoogleAnalytics_LogLevel>(log_level));
callback_to_call(firebase_log_level, message);
}
}
// Allows the passing of a callback to be used when the SDK logs any
// messages regarding its behavior. The callback must be thread-safe.
void SetLogCallback(const LogCallback& callback) {
FIREBASE_ASSERT_RETURN_VOID(internal::IsInitialized());
// The C API does not support user data, so we must use a global variable.
{
std::lock_guard<std::mutex> lock(g_log_callback_mutex);
g_log_callback = callback;
}
if (callback) {
GoogleAnalytics_SetLogCallback(GoogleAnalyticsWrapperLogCallback);
} else {
GoogleAnalytics_SetLogCallback(nullptr);
}
}
// Notify the Analytics SDK about the current state of the app's lifecycle.
void NotifyAppLifecycleChange(AppLifecycleState state) {
FIREBASE_ASSERT_RETURN_VOID(internal::IsInitialized());
GoogleAnalytics_NotifyAppLifecycleChange(
static_cast<GoogleAnalytics_AppLifecycleState>(state));
}
// Returns true if the desktop Analytics dll is initialized.
bool IsDesktopInitialized() {
FIREBASE_ASSERT_RETURN(false, internal::IsInitialized());
return GoogleAnalytics_IsInitialized();
}
// Sends the enabled Flag to the desktop Analytics dll.
void SetDesktopDebugMode(bool enabled) {
FIREBASE_ASSERT_RETURN_VOID(internal::IsInitialized());
GoogleAnalytics_SetDebugMode(enabled);
}
// Overloaded versions of LogEvent for convenience.
void LogEvent(const char* name) {
LogEvent(name, static_cast<const Parameter*>(nullptr), 0);
}
/// Log an Apple StoreKit 2 transaction. This is a no-op on Desktop and returns
/// success.
Future<void> LogAppleTransaction(const char* transaction_id) {
auto* api = internal::FutureData::Get() ? internal::FutureData::Get()->api()
: nullptr;
if (!api) {
return Future<void>();
}
const auto future_handle =
api->SafeAlloc<void>(internal::kAnalyticsFnLogAppleTransaction);
api->Complete(future_handle, 0, "");
return Future<void>(api, future_handle.get());
}
Future<void> LogAppleTransactionLastResult() {
auto* api = internal::FutureData::Get() ? internal::FutureData::Get()->api()
: nullptr;
if (!api) {
return Future<void>();
}
return static_cast<const Future<void>&>(
api->LastResult(internal::kAnalyticsFnLogAppleTransaction));
}
void LogEvent(const char* name, const char* parameter_name,
const char* parameter_value) {
if (parameter_name == nullptr) {
LogEvent(name, static_cast<const Parameter*>(nullptr), 0);
return;
}
Parameter param(parameter_name, parameter_value);
LogEvent(name, ¶m, 1);
}
void LogEvent(const char* name, const char* parameter_name,
const double parameter_value) {
if (parameter_name == nullptr) {
LogEvent(name, static_cast<const Parameter*>(nullptr), 0);
return;
}
Parameter param(parameter_name, parameter_value);
LogEvent(name, ¶m, 1);
}
void LogEvent(const char* name, const char* parameter_name,
const int64_t parameter_value) {
if (parameter_name == nullptr) {
LogEvent(name, static_cast<const Parameter*>(nullptr), 0);
return;
}
Parameter param(parameter_name, parameter_value);
LogEvent(name, ¶m, 1);
}
void LogEvent(const char* name, const char* parameter_name,
const int parameter_value) {
if (parameter_name == nullptr) {
LogEvent(name, static_cast<const Parameter*>(nullptr), 0);
return;
}
Parameter param(parameter_name, static_cast<int64_t>(parameter_value));
LogEvent(name, ¶m, 1);
}
// --- Stub Implementations for Unsupported Features ---
void SetDefaultEventParameters(const Parameter* parameters,
size_t number_of_parameters) {
FIREBASE_ASSERT_RETURN_VOID(internal::IsInitialized());
}
void SetDefaultEventParameters(const std::vector<Parameter>& parameters) {
SetDefaultEventParameters(parameters.data(), parameters.size());
}
void SetConsent(const std::map<ConsentType, ConsentStatus>& consent_settings) {
FIREBASE_ASSERT_RETURN_VOID(internal::IsInitialized());
// Not supported by the Windows C API.
(void)consent_settings; // Mark as unused
#if defined(_WIN32)
if (g_analytics_module) {
// Only log this if we are not in stub mode.
LogWarning(
"Analytics: SetConsent() is not supported and has no effect on "
"Desktop.");
}
#endif // defined(_WIN32)
}
void InitiateOnDeviceConversionMeasurementWithEmailAddress(
const char* email_address) {
FIREBASE_ASSERT_RETURN_VOID(internal::IsInitialized());
(void)email_address;
#if defined(_WIN32)
if (g_analytics_module) {
// Only log this if we are not in stub mode.
LogWarning(
"Analytics: InitiateOnDeviceConversionMeasurementWithEmailAddress() is "
"not supported and has no effect on Desktop.");
}
#endif // defined(_WIN32)
}
void InitiateOnDeviceConversionMeasurementWithPhoneNumber(
const char* phone_number) {
FIREBASE_ASSERT_RETURN_VOID(internal::IsInitialized());
(void)phone_number;
#if defined(_WIN32)
if (g_analytics_module) {
// Only log this if we are not in stub mode.
LogWarning(
"Analytics: InitiateOnDeviceConversionMeasurementWithPhoneNumber() is "
"not supported and has no effect on Desktop.");
}
#endif // defined(_WIN32)
}
void InitiateOnDeviceConversionMeasurementWithHashedEmailAddress(
std::vector<unsigned char> hashed_email_address) {
FIREBASE_ASSERT_RETURN_VOID(internal::IsInitialized());
(void)hashed_email_address;
#if defined(_WIN32)
if (g_analytics_module) {
// Only log this if we are not in stub mode.
LogWarning(
"Analytics: "
"InitiateOnDeviceConversionMeasurementWithHashedEmailAddress() is not "
"supported and has no effect on Desktop.");
}
#endif // defined(_WIN32)
}
void InitiateOnDeviceConversionMeasurementWithHashedPhoneNumber(
std::vector<unsigned char> hashed_phone_number) {
FIREBASE_ASSERT_RETURN_VOID(internal::IsInitialized());
(void)hashed_phone_number;
#if defined(_WIN32)
if (g_analytics_module) {
// Only log this if we are not in stub mode.
LogWarning(
"Analytics: "
"InitiateOnDeviceConversionMeasurementWithHashedPhoneNumber() "
"is not supported and has no effect on Desktop.");
}
#endif // defined(_WIN32)
}
void SetSessionTimeoutDuration(int64_t milliseconds) {
FIREBASE_ASSERT_RETURN_VOID(internal::IsInitialized());
(void)milliseconds;
#if defined(_WIN32)
if (g_analytics_module) {
// Only log this if we are not in stub mode.
LogWarning(
"Analytics: SetSessionTimeoutDuration() is not supported and has no "
"effect on Desktop.");
}
#endif // defined(_WIN32)
}
Future<std::string> GetAnalyticsInstanceId() {
FIREBASE_ASSERT_RETURN(Future<std::string>(), internal::IsInitialized());
auto* api = internal::FutureData::Get()->api();
const auto future_handle =
api->SafeAlloc<std::string>(internal::kAnalyticsFnGetAnalyticsInstanceId);
std::string instance_id = std::string("FakeAnalyticsInstanceId");
{
std::stringstream ss;
ss << g_fake_instance_id;
instance_id += ss.str();
}
api->CompleteWithResult(future_handle, 0, "", instance_id);
#if defined(_WIN32)
if (g_analytics_module) {
// Only log this if we are not in stub mode.
LogWarning(
"Analytics: GetAnalyticsInstanceId() is not supported on Desktop.");
}
#endif // defined(_WIN32)
return Future<std::string>(api, future_handle.get());
}
Future<std::string> GetAnalyticsInstanceIdLastResult() {
FIREBASE_ASSERT_RETURN(Future<std::string>(), internal::IsInitialized());
LogWarning(
"Analytics: GetAnalyticsInstanceIdLastResult() is not supported on "
"Desktop.");
return static_cast<const Future<std::string>&>(
internal::FutureData::Get()->api()->LastResult(
internal::kAnalyticsFnGetAnalyticsInstanceId));
}
Future<int64_t> GetSessionId() {
FIREBASE_ASSERT_RETURN(Future<int64_t>(), internal::IsInitialized());
auto* api = internal::FutureData::Get()->api();
const auto future_handle =
api->SafeAlloc<int64_t>(internal::kAnalyticsFnGetSessionId);
int64_t session_id = 0x5E5510171D570BL; // "SESSIONIDSTUB", kinda
api->CompleteWithResult(future_handle, 0, "", session_id);
#if defined(_WIN32)
if (g_analytics_module) {
// Only log this if we are not in stub mode.
LogWarning("Analytics: GetSessionId() is not supported on Desktop.");
}
#endif // defined(_WIN32)
return Future<int64_t>(api, future_handle.get());
}
Future<int64_t> GetSessionIdLastResult() {
FIREBASE_ASSERT_RETURN(Future<int64_t>(), internal::IsInitialized());
#if defined(_WIN32)
if (g_analytics_module) {
// Only log this if we are not in stub mode.
LogWarning(
"Analytics: GetSessionIdLastResult() is not supported on Desktop.");
}
#endif // defined(_WIN32)
return static_cast<const Future<int64_t>&>(
internal::FutureData::Get()->api()->LastResult(
internal::kAnalyticsFnGetSessionId));
}
} // namespace analytics
} // namespace firebase