-
Notifications
You must be signed in to change notification settings - Fork 120
/
Copy pathanalytics_stub.cc
196 lines (164 loc) · 6.65 KB
/
analytics_stub.cc
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
/*
* Copyright 2016 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 <sstream>
#include "analytics/src/analytics_common.h"
#include "analytics/src/include/firebase/analytics.h"
#include "app/src/assert.h"
#include "app/src/include/firebase/version.h"
namespace firebase {
namespace analytics {
DEFINE_FIREBASE_VERSION_STRING(FirebaseAnalytics);
static bool g_initialized = false;
static int g_fake_instance_id = 0;
// Initialize the API.
void Initialize(const ::firebase::App& /*app*/) {
g_initialized = true;
internal::RegisterTerminateOnDefaultAppDestroy();
internal::FutureData::Create();
g_fake_instance_id = 0;
}
namespace internal {
// Determine whether the analytics module is initialized.
bool IsInitialized() { return g_initialized; }
} // namespace internal
// Terminate the API.
void Terminate() {
internal::FutureData::Destroy();
internal::UnregisterTerminateOnDefaultAppDestroy();
g_initialized = false;
}
// Enable / disable measurement and reporting.
void SetAnalyticsCollectionEnabled(bool /*enabled*/) {
FIREBASE_ASSERT_RETURN_VOID(internal::IsInitialized());
}
// Enable / disable measurement and reporting.
void SetConsent(const std::map<ConsentType, ConsentStatus>& consent_settings) {
FIREBASE_ASSERT_RETURN_VOID(internal::IsInitialized());
}
// Log an event with one string parameter.
void LogEvent(const char* /*name*/, const char* /*parameter_name*/,
const char* /*parameter_value*/) {
FIREBASE_ASSERT_RETURN_VOID(internal::IsInitialized());
}
// Log an event with one double parameter.
void LogEvent(const char* /*name*/, const char* /*parameter_name*/,
const double /*parameter_value*/) {
FIREBASE_ASSERT_RETURN_VOID(internal::IsInitialized());
}
// Log an event with one 64-bit integer parameter.
void LogEvent(const char* /*name*/, const char* /*parameter_name*/,
const int64_t /*parameter_value*/) {
FIREBASE_ASSERT_RETURN_VOID(internal::IsInitialized());
}
// Log an event with one integer parameter (stored as a 64-bit integer).
void LogEvent(const char* name, const char* parameter_name,
const int parameter_value) {
LogEvent(name, parameter_name, static_cast<int64_t>(parameter_value));
}
// Log an event with no parameters.
void LogEvent(const char* name) {
LogEvent(name, static_cast<const Parameter*>(nullptr),
static_cast<size_t>(0));
}
// Log an event with associated parameters.
void LogEvent(const char* /*name*/, const Parameter* /*parameters*/,
size_t /*number_of_parameters*/) {
FIREBASE_ASSERT_RETURN_VOID(internal::IsInitialized());
}
/// Initiates on-device conversion measurement given a user email address on iOS
/// (no-op on Android). On iOS, requires dependency
/// GoogleAppMeasurementOnDeviceConversion to be linked in, otherwise it is a
/// no-op.
void InitiateOnDeviceConversionMeasurementWithEmailAddress(
const char* email_address) {
FIREBASE_ASSERT_RETURN_VOID(internal::IsInitialized());
}
void InitiateOnDeviceConversionMeasurementWithHashedEmailAddress(
std::vector<unsigned char> email_address) {
FIREBASE_ASSERT_RETURN_VOID(internal::IsInitialized());
}
/// Initiates on-device conversion measurement given a phone number on iOS
/// (no-op on Android). On iOS, requires dependency
/// GoogleAppMeasurementOnDeviceConversion to be linked in, otherwise it is a
/// no-op.
void InitiateOnDeviceConversionMeasurementWithPhoneNumber(
const char* phone_number) {
FIREBASE_ASSERT_RETURN_VOID(internal::IsInitialized());
}
void InitiateOnDeviceConversionMeasurementWithHashedPhoneNumber(
std::vector<unsigned char> phone_number_hash) {
FIREBASE_ASSERT_RETURN_VOID(internal::IsInitialized());
}
// Set a user property to the given value.
void SetUserProperty(const char* /*name*/, const char* /*value*/) {
FIREBASE_ASSERT_RETURN_VOID(internal::IsInitialized());
}
// Sets the user ID property. This feature must be used in accordance with
// <a href="https://www.google.com/policies/privacy">
// Google's Privacy Policy</a>
void SetUserId(const char* /*user_id*/) {
FIREBASE_ASSERT_RETURN_VOID(internal::IsInitialized());
}
// Sets the duration of inactivity that terminates the current session.
void SetSessionTimeoutDuration(int64_t /*milliseconds*/) {
FIREBASE_ASSERT_RETURN_VOID(internal::IsInitialized());
}
void ResetAnalyticsData() {
FIREBASE_ASSERT_RETURN_VOID(internal::IsInitialized());
g_fake_instance_id++;
}
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);
return Future<std::string>(api, future_handle.get());
}
Future<std::string> GetAnalyticsInstanceIdLastResult() {
FIREBASE_ASSERT_RETURN(Future<std::string>(), internal::IsInitialized());
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);
return Future<int64_t>(api, future_handle.get());
}
Future<int64_t> GetSessionIdLastResult() {
FIREBASE_ASSERT_RETURN(Future<int64_t>(), internal::IsInitialized());
return static_cast<const Future<int64_t>&>(
internal::FutureData::Get()->api()->LastResult(
internal::kAnalyticsFnGetSessionId));
}
// Sets the default parameters to be sent with each event.
void SetDefaultEventParameters(
const std::map<std::string, Variant>& parameters) {
FIREBASE_ASSERT_RETURN_VOID(internal::IsInitialized());
}
} // namespace analytics
} // namespace firebase