Skip to content

Commit 7cdfc29

Browse files
committed
Update to use the latest analytics dll and source headers to account for latest changes.
Add latest google_analytics.dll and corresponding public header files. Also added the implementations for SetLogCallback and NotifyAppLifecycleChange.
1 parent 292c799 commit 7cdfc29

14 files changed

+487
-71
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ __pycache__/
1717

1818
### IDE generated files
1919
.vscode/
20+
**/.vs/
2021

2122
# Unencrypted secret files
2223
google-services.json

analytics/generate_windows_stubs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ def generate_function_pointers(dll_file_path, header_file_path, output_h_path, o
262262
)
263263
parser.add_argument(
264264
"--windows_dll",
265-
default = os.path.join(os.path.dirname(sys.argv[0]), "windows/analytics_win.dll"),
265+
default = os.path.join(os.path.dirname(sys.argv[0]), "windows/google_analytics.dll"),
266266
help="Path to the DLL file to calculate a hash."
267267
)
268268
parser.add_argument(

analytics/integration_test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ else()
211211
)
212212
elseif(MSVC)
213213
set(ADDITIONAL_LIBS advapi32 ws2_32 crypt32)
214-
set(ANALYTICS_WINDOWS_DLL "${FIREBASE_CPP_SDK_DIR}/analytics/windows/analytics_win.dll")
214+
set(ANALYTICS_WINDOWS_DLL "${FIREBASE_CPP_SDK_DIR}/analytics/windows/google_analytics.dll")
215215

216216
# For Windows, check if the Analytics DLL exists, and copy it in if so.
217217
if (EXISTS "${ANALYTICS_WINDOWS_DLL}")

analytics/src/analytics_desktop.cc

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace firebase {
3636
namespace analytics {
3737

3838
#if defined(_WIN32)
39-
#define ANALYTICS_DLL_FILENAME L"analytics_win.dll"
39+
#define ANALYTICS_DLL_FILENAME L"google_analytics.dll"
4040

4141
static HMODULE g_analytics_module = 0;
4242
#endif // defined(_WIN32)
@@ -134,6 +134,10 @@ bool IsInitialized() { return g_initialized; }
134134
void Terminate() {
135135
#if defined(_WIN32)
136136
if (g_analytics_module) {
137+
// Make sure to notify the SDK that the analytics is being terminated to
138+
// upload any pending data.
139+
NotifyAppLifecycleChange(AppLifecycleState::kTermination);
140+
137141
FirebaseAnalytics_UnloadDynamicFunctions();
138142
FreeLibrary(g_analytics_module);
139143
g_analytics_module = 0;
@@ -381,6 +385,46 @@ void ResetAnalyticsData() {
381385
g_fake_instance_id++;
382386
}
383387

388+
// Notify the Analytics SDK about the current state of the app's lifecycle.
389+
void NotifyAppLifecycleChange(AppLifecycleState state) {
390+
FIREBASE_ASSERT_RETURN_VOID(internal::IsInitialized());
391+
GoogleAnalytics_NotifyAppLifecycleChange(
392+
static_cast<GoogleAnalytics_AppLifecycleState>(state));
393+
}
394+
395+
static void (*firebaseLogCallback)(LogLevel log_level, const char* log_message,
396+
void* callback_data) = nullptr;
397+
398+
void SetLogCallback(LogCallback callback) {
399+
FIREBASE_ASSERT_RETURN_VOID(internal::IsInitialized());
400+
401+
firebaseLogCallback = callback;
402+
403+
GoogleAnalytics_SetLogCallback(
404+
[](GoogleAnalytics_LogLevel log_level, const char* message) {
405+
if (firebaseLogCallback) {
406+
LogLevel fbLogLevel;
407+
switch (log_level) {
408+
case GoogleAnalytics_LogLevel::kDebug:
409+
fbLogLevel = LogLevel::kLogLevelDebug;
410+
break;
411+
case GoogleAnalytics_LogLevel::kInfo:
412+
fbLogLevel = LogLevel::kLogLevelInfo;
413+
break;
414+
case GoogleAnalytics_LogLevel::kWarning:
415+
fbLogLevel = LogLevel::kLogLevelWarning;
416+
break;
417+
case GoogleAnalytics_LogLevel::kError:
418+
fbLogLevel = LogLevel::kLogLevelError;
419+
break;
420+
default:
421+
fbLogLevel = LogLevel::kLogLevelInfo;
422+
}
423+
firebaseLogCallback(fbLogLevel, message, nullptr);
424+
}
425+
});
426+
}
427+
384428
// Overloaded versions of LogEvent for convenience.
385429

386430
void LogEvent(const char* name) {

analytics/src/analytics_desktop_dynamic.c

Lines changed: 64 additions & 40 deletions
Large diffs are not rendered by default.

analytics/src/analytics_desktop_dynamic.h

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ typedef struct GoogleAnalytics_Reserved_Opaque GoogleAnalytics_Reserved;
3434
* using GoogleAnalytics_Options_Create(), initialization will fail, and the
3535
* caller will be responsible for destroying the options.
3636
*/
37-
ANALYTICS_API typedef struct {
37+
typedef struct ANALYTICS_API GoogleAnalytics_Options {
3838
/**
3939
* @brief The unique identifier for the Firebase app across all of Firebase
4040
* with a platform-specific format. This is a required field, can not be null
@@ -68,12 +68,54 @@ ANALYTICS_API typedef struct {
6868
*/
6969
bool analytics_collection_enabled_at_first_launch;
7070

71+
/**
72+
* @brief An optional path to a folder where the SDK can store its data.
73+
* If not provided, the SDK will store its data in the same folder as the
74+
* executable.
75+
*
76+
* The path must pre-exist and the app has read and write access to it.
77+
*/
78+
const char* app_data_directory;
79+
7180
/**
7281
* @brief Reserved for internal use by the SDK.
7382
*/
7483
GoogleAnalytics_Reserved* reserved;
7584
} GoogleAnalytics_Options;
7685

86+
/**
87+
* @brief The state of an app in its lifecycle.
88+
*/
89+
typedef enum GoogleAnalytics_AppLifecycleState {
90+
/**
91+
* @brief This is an invalid state that is used to capture unininitialized
92+
* values.
93+
*/
94+
GoogleAnalytics_AppLifecycleState_kUnknown = 0,
95+
/**
96+
* @brief The app is about to be terminated.
97+
*/
98+
GoogleAnalytics_AppLifecycleState_kTermination = 1,
99+
} GoogleAnalytics_AppLifecycleState;
100+
101+
/**
102+
* @brief The log level of a log message.
103+
*/
104+
typedef enum GoogleAnalytics_LogLevel {
105+
kDebug,
106+
kInfo,
107+
kWarning,
108+
kError,
109+
} GoogleAnalytics_LogLevel;
110+
111+
/**
112+
* @brief Function pointer type for a log callback.
113+
*
114+
* @param[in] message The log message string.
115+
*/
116+
typedef void (*GoogleAnalytics_LogCallback)(GoogleAnalytics_LogLevel log_level,
117+
const char* message);
118+
77119
/**
78120
* @brief Creates an instance of GoogleAnalytics_Options with default values.
79121
*
@@ -149,25 +191,27 @@ extern "C" {
149191
extern GoogleAnalytics_Options* (*ptr_GoogleAnalytics_Options_Create)();
150192
extern void (*ptr_GoogleAnalytics_Options_Destroy)(GoogleAnalytics_Options* options);
151193
extern GoogleAnalytics_Item* (*ptr_GoogleAnalytics_Item_Create)();
152-
extern void (*ptr_GoogleAnalytics_Item_InsertInt)(GoogleAnalytics_Item* item, const char* key, int64_t value);
153-
extern void (*ptr_GoogleAnalytics_Item_InsertDouble)(GoogleAnalytics_Item* item, const char* key, double value);
154-
extern void (*ptr_GoogleAnalytics_Item_InsertString)(GoogleAnalytics_Item* item, const char* key, const char* value);
194+
extern bool (*ptr_GoogleAnalytics_Item_InsertInt)(GoogleAnalytics_Item* item, const char* key, int64_t value);
195+
extern bool (*ptr_GoogleAnalytics_Item_InsertDouble)(GoogleAnalytics_Item* item, const char* key, double value);
196+
extern bool (*ptr_GoogleAnalytics_Item_InsertString)(GoogleAnalytics_Item* item, const char* key, const char* value);
155197
extern void (*ptr_GoogleAnalytics_Item_Destroy)(GoogleAnalytics_Item* item);
156198
extern GoogleAnalytics_ItemVector* (*ptr_GoogleAnalytics_ItemVector_Create)();
157-
extern void (*ptr_GoogleAnalytics_ItemVector_InsertItem)(GoogleAnalytics_ItemVector* item_vector, GoogleAnalytics_Item* item);
199+
extern bool (*ptr_GoogleAnalytics_ItemVector_InsertItem)(GoogleAnalytics_ItemVector* item_vector, GoogleAnalytics_Item* item);
158200
extern void (*ptr_GoogleAnalytics_ItemVector_Destroy)(GoogleAnalytics_ItemVector* item_vector);
159201
extern GoogleAnalytics_EventParameters* (*ptr_GoogleAnalytics_EventParameters_Create)();
160-
extern void (*ptr_GoogleAnalytics_EventParameters_InsertInt)(GoogleAnalytics_EventParameters* event_parameter_map, const char* key, int64_t value);
161-
extern void (*ptr_GoogleAnalytics_EventParameters_InsertDouble)(GoogleAnalytics_EventParameters* event_parameter_map, const char* key, double value);
162-
extern void (*ptr_GoogleAnalytics_EventParameters_InsertString)(GoogleAnalytics_EventParameters* event_parameter_map, const char* key, const char* value);
163-
extern void (*ptr_GoogleAnalytics_EventParameters_InsertItemVector)(GoogleAnalytics_EventParameters* event_parameter_map, const char* key, GoogleAnalytics_ItemVector* value);
202+
extern bool (*ptr_GoogleAnalytics_EventParameters_InsertInt)(GoogleAnalytics_EventParameters* event_parameter_map, const char* key, int64_t value);
203+
extern bool (*ptr_GoogleAnalytics_EventParameters_InsertDouble)(GoogleAnalytics_EventParameters* event_parameter_map, const char* key, double value);
204+
extern bool (*ptr_GoogleAnalytics_EventParameters_InsertString)(GoogleAnalytics_EventParameters* event_parameter_map, const char* key, const char* value);
205+
extern bool (*ptr_GoogleAnalytics_EventParameters_InsertItemVector)(GoogleAnalytics_EventParameters* event_parameter_map, const char* key, GoogleAnalytics_ItemVector* value);
164206
extern void (*ptr_GoogleAnalytics_EventParameters_Destroy)(GoogleAnalytics_EventParameters* event_parameter_map);
165-
extern bool (*ptr_GoogleAnalytics_Initialize)(const GoogleAnalytics_Options* options);
207+
extern bool (*ptr_GoogleAnalytics_Initialize)(GoogleAnalytics_Options* options);
166208
extern void (*ptr_GoogleAnalytics_LogEvent)(const char* name, GoogleAnalytics_EventParameters* parameters);
167209
extern void (*ptr_GoogleAnalytics_SetUserProperty)(const char* name, const char* value);
168210
extern void (*ptr_GoogleAnalytics_SetUserId)(const char* user_id);
169211
extern void (*ptr_GoogleAnalytics_ResetAnalyticsData)();
170212
extern void (*ptr_GoogleAnalytics_SetAnalyticsCollectionEnabled)(bool enabled);
213+
extern void (*ptr_GoogleAnalytics_SetLogCallback)(GoogleAnalytics_LogCallback callback);
214+
extern void (*ptr_GoogleAnalytics_NotifyAppLifecycleChange)(GoogleAnalytics_AppLifecycleState state);
171215

172216
#define GoogleAnalytics_Options_Create ptr_GoogleAnalytics_Options_Create
173217
#define GoogleAnalytics_Options_Destroy ptr_GoogleAnalytics_Options_Destroy
@@ -191,6 +235,8 @@ extern void (*ptr_GoogleAnalytics_SetAnalyticsCollectionEnabled)(bool enabled);
191235
#define GoogleAnalytics_SetUserId ptr_GoogleAnalytics_SetUserId
192236
#define GoogleAnalytics_ResetAnalyticsData ptr_GoogleAnalytics_ResetAnalyticsData
193237
#define GoogleAnalytics_SetAnalyticsCollectionEnabled ptr_GoogleAnalytics_SetAnalyticsCollectionEnabled
238+
#define GoogleAnalytics_SetLogCallback ptr_GoogleAnalytics_SetLogCallback
239+
#define GoogleAnalytics_NotifyAppLifecycleChange ptr_GoogleAnalytics_NotifyAppLifecycleChange
194240
// clang-format on
195241

196242
// Number of Google Analytics functions expected to be loaded from the DLL.

analytics/src/include/firebase/analytics.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,38 @@ void SetSessionTimeoutDuration(int64_t milliseconds);
558558
/// instance id.
559559
void ResetAnalyticsData();
560560

561+
562+
/// @brief The state of an app in its lifecycle.
563+
///
564+
/// kUnknown is an invalid sate that is used to capture uninitialized values.
565+
/// kTermination is used to indicate that the app is about to be terminated.
566+
enum AppLifecycleState {
567+
kUnknown = 0,
568+
kTermination
569+
};
570+
571+
/// @brief Notifies the current state of the app's lifecycle.
572+
///
573+
/// This method is used to notify the Analytics SDK about the current state of
574+
/// the app's lifecycle. The Analytics SDK will use this information to log
575+
/// events, update user properties, upload data, etc.
576+
///
577+
/// kTermination is used to indicate that the app is about to be terminated.
578+
/// The caller will be blocked until all pending data is uploaded or an error
579+
/// occurs. The caller must ensure the OS does not terminate background threads
580+
/// before the call returns.
581+
///
582+
/// @param[in] state The current state of the app's lifecycle.
583+
584+
void NotifyAppLifecycleChange(AppLifecycleState state);
585+
586+
/// @brief Allows the passing of a callback to be used when the SDK logs any
587+
/// *messages regarding its behavior.The callback must be thread -
588+
/// safe.
589+
///
590+
/// @param[in] callback The callback to use. Must be thread-safe.
591+
void SetLogCallback(LogCallback callback);
592+
561593
/// Get the instance ID from the analytics service.
562594
///
563595
/// @note This is *not* the same ID as the ID returned by
-19.7 MB
Binary file not shown.
8.7 MB
Binary file not shown.

0 commit comments

Comments
 (0)