Skip to content

Commit de68294

Browse files
authored
Merge 737f99d into 292c799
2 parents 292c799 + 737f99d commit de68294

15 files changed

+450
-69
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/integration_test/src/integration_test.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,14 @@ TEST_F(FirebaseAnalyticsTest, TestLogEvents) {
259259
"spoon_welders");
260260
}
261261

262+
TEST_F(FirebaseAnalyticsTest, TestNotifyAppLifecycleChange) {
263+
// Can't confirm that these do anything but just run them all to ensure the
264+
// app doesn't crash.
265+
firebase::analytics::NotifyAppLifecycleChange(firebase::analytics::kUnknown);
266+
firebase::analytics::NotifyAppLifecycleChange(
267+
firebase::analytics::kTermination);
268+
}
269+
262270
TEST_F(FirebaseAnalyticsTest, TestLogEventWithMultipleParameters) {
263271
const firebase::analytics::Parameter kLevelUpParameters[] = {
264272
firebase::analytics::Parameter(firebase::analytics::kParameterLevel, 5),

analytics/src/analytics_desktop.cc

Lines changed: 12 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,13 @@ 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+
384395
// Overloaded versions of LogEvent for convenience.
385396

386397
void LogEvent(const char* name) {

analytics/src/analytics_desktop_dynamic.c

Lines changed: 63 additions & 38 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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,27 @@ void SetSessionTimeoutDuration(int64_t milliseconds);
558558
/// instance id.
559559
void ResetAnalyticsData();
560560

561+
/// @brief The state of an app in its lifecycle.
562+
///
563+
/// kUnknown is an invalid state that is used to capture uninitialized values.
564+
/// kTermination is used to indicate that the app is about to be terminated.
565+
enum AppLifecycleState { kUnknown = 0, kTermination };
566+
567+
/// @brief Notifies the current state of the app's lifecycle.
568+
///
569+
/// This method is used to notify the Analytics SDK about the current state of
570+
/// the app's lifecycle. The Analytics SDK will use this information to log
571+
/// events, update user properties, upload data, etc.
572+
///
573+
/// kTermination is used to indicate that the app is about to be terminated.
574+
/// The caller will be blocked until all pending data is uploaded or an error
575+
/// occurs. The caller must ensure the OS does not terminate background threads
576+
/// before the call returns.
577+
///
578+
/// @param[in] state The current state of the app's lifecycle.
579+
580+
void NotifyAppLifecycleChange(AppLifecycleState state);
581+
561582
/// Get the instance ID from the analytics service.
562583
///
563584
/// @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)