@@ -51,6 +51,7 @@ static HMODULE g_analytics_module = 0;
51
51
// This is initialized in `Initialize()` and cleaned up in `Terminate()`.
52
52
static bool g_initialized = false ;
53
53
static int g_fake_instance_id = 0 ;
54
+ static bool g_analytics_collection_enabled = true ;
54
55
55
56
// Initializes the Analytics desktop API.
56
57
// This function must be called before any other Analytics methods.
@@ -99,9 +100,8 @@ void Initialize(const App& app) {
99
100
} else {
100
101
c_options->app_id = current_app_id.c_str ();
101
102
c_options->package_name = current_package_name.c_str ();
102
- c_options->analytics_collection_enabled_at_first_launch = true ;
103
- // c_options->reserved is initialized by
104
- // GoogleAnalytics_Options_Create
103
+ c_options->analytics_collection_enabled_at_first_launch =
104
+ g_analytics_collection_enabled;
105
105
106
106
LogInfo (
107
107
" Analytics: Initializing Google Analytics C API with App ID: %s, "
@@ -144,7 +144,7 @@ void Terminate() {
144
144
FreeLibrary (g_analytics_module);
145
145
g_analytics_module = 0 ;
146
146
}
147
- #endif
147
+ #endif // defined(_WIN32)
148
148
149
149
internal::FutureData::Destroy ();
150
150
internal::UnregisterTerminateOnDefaultAppDestroy ();
@@ -178,10 +178,15 @@ static void ConvertParametersToGAParams(
178
178
// Vector types for top-level event parameters are not supported on
179
179
// Desktop. Only specific complex types (like a map processed into an
180
180
// ItemVector) are handled.
181
- LogError (
182
- " Analytics: Parameter '%s' has type Vector, which is unsupported for "
183
- " event parameters on Desktop. Skipping." ,
184
- param.name );
181
+ #if defined(_WIN32)
182
+ if (g_analytics_module) {
183
+ // Only log this if we are not in stub mode.
184
+ LogError (
185
+ " Analytics: Parameter '%s' has type Vector, which is unsupported for "
186
+ " event parameters on Desktop. Skipping." ,
187
+ param.name );
188
+ }
189
+ #endif // defined(_WIN32)
185
190
continue ; // Skip this parameter
186
191
} else if (param.value .is_map ()) {
187
192
// This block handles parameters that are maps.
@@ -365,9 +370,11 @@ void SetUserId(const char* user_id) {
365
370
//
366
371
// @param[in] enabled A flag that enables or disables Analytics collection.
367
372
void SetAnalyticsCollectionEnabled (bool enabled) {
368
- FIREBASE_ASSERT_RETURN_VOID ( internal::IsInitialized ()) ;
373
+ g_analytics_collection_enabled = enabled ;
369
374
370
- GoogleAnalytics_SetAnalyticsCollectionEnabled (enabled);
375
+ if (internal::IsInitialized ()) {
376
+ GoogleAnalytics_SetAnalyticsCollectionEnabled (enabled);
377
+ }
371
378
}
372
379
373
380
// Clears all analytics data for this app from the device and resets the app
@@ -432,53 +439,83 @@ void SetConsent(const std::map<ConsentType, ConsentStatus>& consent_settings) {
432
439
433
440
// Not supported by the Windows C API.
434
441
(void )consent_settings; // Mark as unused
435
- LogWarning (
436
- " Analytics: SetConsent() is not supported and has no effect on Desktop." );
442
+ #if defined(_WIN32)
443
+ if (g_analytics_module) {
444
+ // Only log this if we are not in stub mode.
445
+ LogWarning (
446
+ " Analytics: SetConsent() is not supported and has no effect on Desktop." );
447
+ }
448
+ #endif // defined(_WIN32)
437
449
}
438
450
439
451
void InitiateOnDeviceConversionMeasurementWithEmailAddress (
440
452
const char * email_address) {
441
453
FIREBASE_ASSERT_RETURN_VOID (internal::IsInitialized ());
442
454
(void )email_address;
443
- LogWarning (
444
- " Analytics: InitiateOnDeviceConversionMeasurementWithEmailAddress() is "
445
- " not supported and has no effect on Desktop." );
455
+ #if defined(_WIN32)
456
+ if (g_analytics_module) {
457
+ // Only log this if we are not in stub mode.
458
+ LogWarning (
459
+ " Analytics: InitiateOnDeviceConversionMeasurementWithEmailAddress() is "
460
+ " not supported and has no effect on Desktop." );
461
+ }
462
+ #endif // defined(_WIN32)
446
463
}
447
464
448
465
void InitiateOnDeviceConversionMeasurementWithPhoneNumber (
449
466
const char * phone_number) {
450
467
FIREBASE_ASSERT_RETURN_VOID (internal::IsInitialized ());
451
468
(void )phone_number;
452
- LogWarning (
453
- " Analytics: InitiateOnDeviceConversionMeasurementWithPhoneNumber() is "
454
- " not supported and has no effect on Desktop." );
469
+ #if defined(_WIN32)
470
+ if (g_analytics_module) {
471
+ // Only log this if we are not in stub mode.
472
+ LogWarning (
473
+ " Analytics: InitiateOnDeviceConversionMeasurementWithPhoneNumber() is "
474
+ " not supported and has no effect on Desktop." );
475
+ }
476
+ #endif // defined(_WIN32)
455
477
}
456
478
457
479
void InitiateOnDeviceConversionMeasurementWithHashedEmailAddress (
458
480
std::vector<unsigned char > hashed_email_address) {
459
481
FIREBASE_ASSERT_RETURN_VOID (internal::IsInitialized ());
460
482
(void )hashed_email_address;
461
- LogWarning (
462
- " Analytics: "
463
- " InitiateOnDeviceConversionMeasurementWithHashedEmailAddress() is not "
464
- " supported and has no effect on Desktop." );
483
+ #if defined(_WIN32)
484
+ if (g_analytics_module) {
485
+ // Only log this if we are not in stub mode.
486
+ LogWarning (
487
+ " Analytics: "
488
+ " InitiateOnDeviceConversionMeasurementWithHashedEmailAddress() is not "
489
+ " supported and has no effect on Desktop." );
490
+ }
491
+ #endif // defined(_WIN32)
465
492
}
466
493
467
494
void InitiateOnDeviceConversionMeasurementWithHashedPhoneNumber (
468
495
std::vector<unsigned char > hashed_phone_number) {
469
496
FIREBASE_ASSERT_RETURN_VOID (internal::IsInitialized ());
470
497
(void )hashed_phone_number;
471
- LogWarning (
472
- " Analytics: InitiateOnDeviceConversionMeasurementWithHashedPhoneNumber() "
473
- " is not supported and has no effect on Desktop." );
498
+ #if defined(_WIN32)
499
+ if (g_analytics_module) {
500
+ // Only log this if we are not in stub mode.
501
+ LogWarning (
502
+ " Analytics: InitiateOnDeviceConversionMeasurementWithHashedPhoneNumber() "
503
+ " is not supported and has no effect on Desktop." );
504
+ }
505
+ #endif // defined(_WIN32)
474
506
}
475
507
476
508
void SetSessionTimeoutDuration (int64_t milliseconds) {
477
509
FIREBASE_ASSERT_RETURN_VOID (internal::IsInitialized ());
478
510
(void )milliseconds;
479
- LogWarning (
480
- " Analytics: SetSessionTimeoutDuration() is not supported and has no "
481
- " effect on Desktop." );
511
+ #if defined(_WIN32)
512
+ if (g_analytics_module) {
513
+ // Only log this if we are not in stub mode.
514
+ LogWarning (
515
+ " Analytics: SetSessionTimeoutDuration() is not supported and has no "
516
+ " effect on Desktop." );
517
+ }
518
+ #endif // defined(_WIN32)
482
519
}
483
520
484
521
Future<std::string> GetAnalyticsInstanceId () {
@@ -493,8 +530,14 @@ Future<std::string> GetAnalyticsInstanceId() {
493
530
instance_id += ss.str ();
494
531
}
495
532
api->CompleteWithResult (future_handle, 0 , " " , instance_id);
496
- LogWarning (
497
- " Analytics: GetAnalyticsInstanceId() is not supported on Desktop." );
533
+
534
+ #if defined(_WIN32)
535
+ if (g_analytics_module) {
536
+ // Only log this if we are not in stub mode.
537
+ LogWarning (
538
+ " Analytics: GetAnalyticsInstanceId() is not supported on Desktop." );
539
+ }
540
+ #endif // defined(_WIN32)
498
541
return Future<std::string>(api, future_handle.get ());
499
542
}
500
543
@@ -515,14 +558,24 @@ Future<int64_t> GetSessionId() {
515
558
api->SafeAlloc <int64_t >(internal::kAnalyticsFnGetSessionId );
516
559
int64_t session_id = 0x5E5510171D570BL ; // "SESSIONIDSTUB", kinda
517
560
api->CompleteWithResult (future_handle, 0 , " " , session_id);
518
- LogWarning (" Analytics: GetSessionId() is not supported on Desktop." );
561
+ #if defined(_WIN32)
562
+ if (g_analytics_module) {
563
+ // Only log this if we are not in stub mode.
564
+ LogWarning (" Analytics: GetSessionId() is not supported on Desktop." );
565
+ }
566
+ #endif // defined(_WIN32)
519
567
return Future<int64_t >(api, future_handle.get ());
520
568
}
521
569
522
570
Future<int64_t > GetSessionIdLastResult () {
523
571
FIREBASE_ASSERT_RETURN (Future<int64_t >(), internal::IsInitialized ());
524
- LogWarning (
525
- " Analytics: GetSessionIdLastResult() is not supported on Desktop." );
572
+ #if defined(_WIN32)
573
+ if (g_analytics_module) {
574
+ // Only log this if we are not in stub mode.
575
+ LogWarning (
576
+ " Analytics: GetSessionIdLastResult() is not supported on Desktop." );
577
+ }
578
+ #endif // defined(_WIN32)
526
579
return static_cast <const Future<int64_t >&>(
527
580
internal::FutureData::Get ()->api ()->LastResult (
528
581
internal::kAnalyticsFnGetSessionId ));
0 commit comments