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