expo-facebook-analytics 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +242 -0
- package/android/build.gradle +60 -0
- package/android/src/main/java/com/nitrofbanalytics/HybridFacebookAnalytics.kt +139 -0
- package/app.plugin.js +1 -0
- package/expo-facebook-analytics.podspec +31 -0
- package/ios/HybridFacebookAnalytics.swift +135 -0
- package/lib/index.d.ts +58 -0
- package/lib/index.js +138 -0
- package/lib/specs/FacebookAnalytics.nitro.d.ts +20 -0
- package/lib/specs/FacebookAnalytics.nitro.js +2 -0
- package/lib/types.d.ts +65 -0
- package/lib/types.js +52 -0
- package/nitro.json +19 -0
- package/nitrogen/generated/.gitattributes +1 -0
- package/nitrogen/generated/android/NitroFBAnalytics+autolinking.cmake +81 -0
- package/nitrogen/generated/android/NitroFBAnalytics+autolinking.gradle +27 -0
- package/nitrogen/generated/android/NitroFBAnalyticsOnLoad.cpp +44 -0
- package/nitrogen/generated/android/NitroFBAnalyticsOnLoad.hpp +25 -0
- package/nitrogen/generated/android/c++/JHybridFacebookAnalyticsSpec.cpp +157 -0
- package/nitrogen/generated/android/c++/JHybridFacebookAnalyticsSpec.hpp +79 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/com/nitrofbanalytics/HybridFacebookAnalyticsSpec.kt +110 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/com/nitrofbanalytics/NitroFBAnalyticsOnLoad.kt +35 -0
- package/nitrogen/generated/ios/NitroFBAnalytics+autolinking.rb +60 -0
- package/nitrogen/generated/ios/NitroFBAnalytics-Swift-Cxx-Bridge.cpp +49 -0
- package/nitrogen/generated/ios/NitroFBAnalytics-Swift-Cxx-Bridge.hpp +171 -0
- package/nitrogen/generated/ios/NitroFBAnalytics-Swift-Cxx-Umbrella.hpp +47 -0
- package/nitrogen/generated/ios/NitroFBAnalyticsAutolinking.mm +33 -0
- package/nitrogen/generated/ios/NitroFBAnalyticsAutolinking.swift +26 -0
- package/nitrogen/generated/ios/c++/HybridFacebookAnalyticsSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridFacebookAnalyticsSpecSwift.hpp +167 -0
- package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_std__optional_std__string_.swift +54 -0
- package/nitrogen/generated/ios/swift/HybridFacebookAnalyticsSpec.swift +69 -0
- package/nitrogen/generated/ios/swift/HybridFacebookAnalyticsSpec_cxx.swift +410 -0
- package/nitrogen/generated/shared/c++/HybridFacebookAnalyticsSpec.cpp +34 -0
- package/nitrogen/generated/shared/c++/HybridFacebookAnalyticsSpec.hpp +78 -0
- package/package.json +66 -0
- package/plugin/build/index.d.ts +13 -0
- package/plugin/build/index.js +42 -0
- package/plugin/build/withFacebookAnalyticsAndroid.d.ts +14 -0
- package/plugin/build/withFacebookAnalyticsAndroid.js +67 -0
- package/plugin/build/withFacebookAnalyticsIOS.d.ts +16 -0
- package/plugin/build/withFacebookAnalyticsIOS.js +96 -0
- package/src/index.ts +161 -0
- package/src/specs/FacebookAnalytics.nitro.ts +47 -0
- package/src/types.ts +67 -0
package/lib/index.js
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AppEvents = exports.AppEventParams = void 0;
|
|
4
|
+
exports.logEvent = logEvent;
|
|
5
|
+
exports.logPurchase = logPurchase;
|
|
6
|
+
exports.logPushNotificationOpen = logPushNotificationOpen;
|
|
7
|
+
exports.setUserID = setUserID;
|
|
8
|
+
exports.clearUserID = clearUserID;
|
|
9
|
+
exports.getUserID = getUserID;
|
|
10
|
+
exports.setUserData = setUserData;
|
|
11
|
+
exports.getAnonymousID = getAnonymousID;
|
|
12
|
+
exports.getAdvertiserID = getAdvertiserID;
|
|
13
|
+
exports.setFlushBehavior = setFlushBehavior;
|
|
14
|
+
exports.flush = flush;
|
|
15
|
+
exports.setPushNotificationsDeviceToken = setPushNotificationsDeviceToken;
|
|
16
|
+
exports.setPushNotificationsRegistrationId = setPushNotificationsRegistrationId;
|
|
17
|
+
const react_native_nitro_modules_1 = require("react-native-nitro-modules");
|
|
18
|
+
var types_1 = require("./types");
|
|
19
|
+
Object.defineProperty(exports, "AppEventParams", { enumerable: true, get: function () { return types_1.AppEventParams; } });
|
|
20
|
+
Object.defineProperty(exports, "AppEvents", { enumerable: true, get: function () { return types_1.AppEvents; } });
|
|
21
|
+
const NativeFBAnalytics = react_native_nitro_modules_1.NitroModules.createHybridObject("FacebookAnalytics");
|
|
22
|
+
/**
|
|
23
|
+
* Log a custom or predefined app event.
|
|
24
|
+
* @param eventName - Event name (use AppEvents constants for predefined events)
|
|
25
|
+
* @param args - Optional valueToSum (number) and/or params object
|
|
26
|
+
*/
|
|
27
|
+
function logEvent(eventName, ...args) {
|
|
28
|
+
let valueToSum = 0;
|
|
29
|
+
let params = {};
|
|
30
|
+
for (const arg of args) {
|
|
31
|
+
if (typeof arg === "number") {
|
|
32
|
+
valueToSum = arg;
|
|
33
|
+
}
|
|
34
|
+
else if (typeof arg === "object") {
|
|
35
|
+
params = arg;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const stringParams = {};
|
|
39
|
+
for (const [key, value] of Object.entries(params)) {
|
|
40
|
+
stringParams[key] = String(value);
|
|
41
|
+
}
|
|
42
|
+
if (Object.keys(stringParams).length > 0) {
|
|
43
|
+
NativeFBAnalytics.logEvent(eventName, valueToSum, stringParams);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
NativeFBAnalytics.logEventWithoutParams(eventName, valueToSum);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Log a purchase event.
|
|
51
|
+
*/
|
|
52
|
+
function logPurchase(purchaseAmount, currencyCode, parameters) {
|
|
53
|
+
const stringParams = {};
|
|
54
|
+
if (parameters) {
|
|
55
|
+
for (const [key, value] of Object.entries(parameters)) {
|
|
56
|
+
stringParams[key] = String(value);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
NativeFBAnalytics.logPurchase(purchaseAmount, currencyCode, stringParams);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Log a push notification open event.
|
|
63
|
+
*/
|
|
64
|
+
function logPushNotificationOpen(payload) {
|
|
65
|
+
const stringPayload = {};
|
|
66
|
+
if (payload) {
|
|
67
|
+
for (const [key, value] of Object.entries(payload)) {
|
|
68
|
+
stringPayload[key] = String(value);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
NativeFBAnalytics.logPushNotificationOpen(stringPayload);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Set the user ID for analytics association.
|
|
75
|
+
*/
|
|
76
|
+
function setUserID(userID) {
|
|
77
|
+
if (userID === null) {
|
|
78
|
+
NativeFBAnalytics.clearUserID();
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
NativeFBAnalytics.setUserID(userID);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Clear the current user ID.
|
|
86
|
+
*/
|
|
87
|
+
function clearUserID() {
|
|
88
|
+
NativeFBAnalytics.clearUserID();
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Get the current user ID.
|
|
92
|
+
*/
|
|
93
|
+
function getUserID() {
|
|
94
|
+
return NativeFBAnalytics.getUserID();
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Set user data for advanced matching.
|
|
98
|
+
*/
|
|
99
|
+
function setUserData(userData) {
|
|
100
|
+
NativeFBAnalytics.setUserData(userData.email, userData.firstName, userData.lastName, userData.phone, userData.dateOfBirth, userData.gender, userData.city, userData.state, userData.zip, userData.country);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Get the anonymous device ID.
|
|
104
|
+
*/
|
|
105
|
+
function getAnonymousID() {
|
|
106
|
+
return NativeFBAnalytics.getAnonymousID();
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Get the advertiser ID (IDFA on iOS, AAID on Android).
|
|
110
|
+
*/
|
|
111
|
+
function getAdvertiserID() {
|
|
112
|
+
return NativeFBAnalytics.getAdvertiserID();
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Set the flush behavior for event batching.
|
|
116
|
+
* @param flushBehavior - 'auto' or 'explicit_only'
|
|
117
|
+
*/
|
|
118
|
+
function setFlushBehavior(flushBehavior) {
|
|
119
|
+
NativeFBAnalytics.setFlushBehavior(flushBehavior);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Flush all queued events to Facebook immediately.
|
|
123
|
+
*/
|
|
124
|
+
function flush() {
|
|
125
|
+
NativeFBAnalytics.flush();
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Set the push notification device token (iOS).
|
|
129
|
+
*/
|
|
130
|
+
function setPushNotificationsDeviceToken(deviceToken) {
|
|
131
|
+
NativeFBAnalytics.setPushNotificationsDeviceToken(deviceToken);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Set the push notification registration ID (Android/FCM).
|
|
135
|
+
*/
|
|
136
|
+
function setPushNotificationsRegistrationId(registrationId) {
|
|
137
|
+
NativeFBAnalytics.setPushNotificationsRegistrationId(registrationId);
|
|
138
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { HybridObject } from "react-native-nitro-modules";
|
|
2
|
+
export interface FacebookAnalytics extends HybridObject<{
|
|
3
|
+
ios: "swift";
|
|
4
|
+
android: "kotlin";
|
|
5
|
+
}> {
|
|
6
|
+
logEvent(eventName: string, valueToSum: number, params: Record<string, string>): void;
|
|
7
|
+
logEventWithoutParams(eventName: string, valueToSum: number): void;
|
|
8
|
+
logPurchase(amount: number, currency: string, params: Record<string, string>): void;
|
|
9
|
+
logPushNotificationOpen(payload: Record<string, string>): void;
|
|
10
|
+
setUserID(userID: string): void;
|
|
11
|
+
clearUserID(): void;
|
|
12
|
+
getUserID(): string | undefined;
|
|
13
|
+
setUserData(email: string | undefined, firstName: string | undefined, lastName: string | undefined, phone: string | undefined, dateOfBirth: string | undefined, gender: string | undefined, city: string | undefined, state: string | undefined, zip: string | undefined, country: string | undefined): void;
|
|
14
|
+
getAnonymousID(): Promise<string | undefined>;
|
|
15
|
+
getAdvertiserID(): Promise<string | undefined>;
|
|
16
|
+
setFlushBehavior(flushBehavior: string): void;
|
|
17
|
+
flush(): void;
|
|
18
|
+
setPushNotificationsDeviceToken(token: string): void;
|
|
19
|
+
setPushNotificationsRegistrationId(registrationId: string): void;
|
|
20
|
+
}
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
export type AppEventsFlushBehavior = "auto" | "explicit_only";
|
|
2
|
+
export type Params = {
|
|
3
|
+
[key: string]: string | number;
|
|
4
|
+
};
|
|
5
|
+
export type UserData = Readonly<{
|
|
6
|
+
email?: string;
|
|
7
|
+
firstName?: string;
|
|
8
|
+
lastName?: string;
|
|
9
|
+
phone?: string;
|
|
10
|
+
dateOfBirth?: string;
|
|
11
|
+
gender?: "m" | "f";
|
|
12
|
+
city?: string;
|
|
13
|
+
state?: string;
|
|
14
|
+
zip?: string;
|
|
15
|
+
country?: string;
|
|
16
|
+
}>;
|
|
17
|
+
/**
|
|
18
|
+
* Predefined Facebook App Event names.
|
|
19
|
+
*/
|
|
20
|
+
export declare const AppEvents: {
|
|
21
|
+
readonly AchievedLevel: "fb_mobile_level_achieved";
|
|
22
|
+
readonly AdClick: "AdClick";
|
|
23
|
+
readonly AdImpression: "AdImpression";
|
|
24
|
+
readonly AddedPaymentInfo: "fb_mobile_add_payment_info";
|
|
25
|
+
readonly AddedToCart: "fb_mobile_add_to_cart";
|
|
26
|
+
readonly AddedToWishlist: "fb_mobile_add_to_wishlist";
|
|
27
|
+
readonly CompletedRegistration: "fb_mobile_complete_registration";
|
|
28
|
+
readonly CompletedTutorial: "fb_mobile_tutorial_completion";
|
|
29
|
+
readonly Contact: "Contact";
|
|
30
|
+
readonly CustomizeProduct: "CustomizeProduct";
|
|
31
|
+
readonly Donate: "Donate";
|
|
32
|
+
readonly FindLocation: "FindLocation";
|
|
33
|
+
readonly InitiatedCheckout: "fb_mobile_initiated_checkout";
|
|
34
|
+
readonly Purchased: "fb_mobile_purchase";
|
|
35
|
+
readonly Rated: "fb_mobile_rate";
|
|
36
|
+
readonly Searched: "fb_mobile_search";
|
|
37
|
+
readonly SpentCredits: "fb_mobile_spent_credits";
|
|
38
|
+
readonly Schedule: "Schedule";
|
|
39
|
+
readonly StartTrial: "StartTrial";
|
|
40
|
+
readonly SubmitApplication: "SubmitApplication";
|
|
41
|
+
readonly Subscribe: "Subscribe";
|
|
42
|
+
readonly UnlockedAchievement: "fb_mobile_achievement_unlocked";
|
|
43
|
+
readonly ViewedContent: "fb_mobile_content_view";
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Predefined Facebook App Event parameter names.
|
|
47
|
+
*/
|
|
48
|
+
export declare const AppEventParams: {
|
|
49
|
+
readonly AddType: "fb_mobile_add_type";
|
|
50
|
+
readonly Content: "fb_content";
|
|
51
|
+
readonly ContentID: "fb_content_id";
|
|
52
|
+
readonly ContentType: "fb_content_type";
|
|
53
|
+
readonly Currency: "fb_currency";
|
|
54
|
+
readonly Description: "fb_description";
|
|
55
|
+
readonly Level: "fb_level";
|
|
56
|
+
readonly NumItems: "fb_num_items";
|
|
57
|
+
readonly MaxRatingValue: "fb_max_rating_value";
|
|
58
|
+
readonly OrderId: "fb_order_id";
|
|
59
|
+
readonly PaymentInfoAvailable: "fb_payment_info_available";
|
|
60
|
+
readonly RegistrationMethod: "fb_registration_method";
|
|
61
|
+
readonly SearchString: "fb_search_string";
|
|
62
|
+
readonly Success: "fb_success";
|
|
63
|
+
readonly ValueNo: "0";
|
|
64
|
+
readonly ValueYes: "1";
|
|
65
|
+
};
|
package/lib/types.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AppEventParams = exports.AppEvents = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Predefined Facebook App Event names.
|
|
6
|
+
*/
|
|
7
|
+
exports.AppEvents = {
|
|
8
|
+
AchievedLevel: "fb_mobile_level_achieved",
|
|
9
|
+
AdClick: "AdClick",
|
|
10
|
+
AdImpression: "AdImpression",
|
|
11
|
+
AddedPaymentInfo: "fb_mobile_add_payment_info",
|
|
12
|
+
AddedToCart: "fb_mobile_add_to_cart",
|
|
13
|
+
AddedToWishlist: "fb_mobile_add_to_wishlist",
|
|
14
|
+
CompletedRegistration: "fb_mobile_complete_registration",
|
|
15
|
+
CompletedTutorial: "fb_mobile_tutorial_completion",
|
|
16
|
+
Contact: "Contact",
|
|
17
|
+
CustomizeProduct: "CustomizeProduct",
|
|
18
|
+
Donate: "Donate",
|
|
19
|
+
FindLocation: "FindLocation",
|
|
20
|
+
InitiatedCheckout: "fb_mobile_initiated_checkout",
|
|
21
|
+
Purchased: "fb_mobile_purchase",
|
|
22
|
+
Rated: "fb_mobile_rate",
|
|
23
|
+
Searched: "fb_mobile_search",
|
|
24
|
+
SpentCredits: "fb_mobile_spent_credits",
|
|
25
|
+
Schedule: "Schedule",
|
|
26
|
+
StartTrial: "StartTrial",
|
|
27
|
+
SubmitApplication: "SubmitApplication",
|
|
28
|
+
Subscribe: "Subscribe",
|
|
29
|
+
UnlockedAchievement: "fb_mobile_achievement_unlocked",
|
|
30
|
+
ViewedContent: "fb_mobile_content_view",
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Predefined Facebook App Event parameter names.
|
|
34
|
+
*/
|
|
35
|
+
exports.AppEventParams = {
|
|
36
|
+
AddType: "fb_mobile_add_type",
|
|
37
|
+
Content: "fb_content",
|
|
38
|
+
ContentID: "fb_content_id",
|
|
39
|
+
ContentType: "fb_content_type",
|
|
40
|
+
Currency: "fb_currency",
|
|
41
|
+
Description: "fb_description",
|
|
42
|
+
Level: "fb_level",
|
|
43
|
+
NumItems: "fb_num_items",
|
|
44
|
+
MaxRatingValue: "fb_max_rating_value",
|
|
45
|
+
OrderId: "fb_order_id",
|
|
46
|
+
PaymentInfoAvailable: "fb_payment_info_available",
|
|
47
|
+
RegistrationMethod: "fb_registration_method",
|
|
48
|
+
SearchString: "fb_search_string",
|
|
49
|
+
Success: "fb_success",
|
|
50
|
+
ValueNo: "0",
|
|
51
|
+
ValueYes: "1",
|
|
52
|
+
};
|
package/nitro.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://nitro.margelo.com/nitro.schema.json",
|
|
3
|
+
"cxxNamespace": ["fbanalytics"],
|
|
4
|
+
"ios": {
|
|
5
|
+
"iosModuleName": "NitroFBAnalytics"
|
|
6
|
+
},
|
|
7
|
+
"android": {
|
|
8
|
+
"androidNamespace": ["com", "nitrofbanalytics"],
|
|
9
|
+
"androidCxxLibName": "NitroFBAnalytics"
|
|
10
|
+
},
|
|
11
|
+
"autolinking": {
|
|
12
|
+
"FacebookAnalytics": {
|
|
13
|
+
"swift": "HybridFacebookAnalytics",
|
|
14
|
+
"kotlin": "HybridFacebookAnalytics"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"ignorePaths": ["node_modules", "lib", "plugin"],
|
|
18
|
+
"gitAttributesGeneratedFlag": true
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
** linguist-generated=true
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
#
|
|
2
|
+
# NitroFBAnalytics+autolinking.cmake
|
|
3
|
+
# This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
# https://github.com/mrousavy/nitro
|
|
5
|
+
# Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
#
|
|
7
|
+
|
|
8
|
+
# This is a CMake file that adds all files generated by Nitrogen
|
|
9
|
+
# to the current CMake project.
|
|
10
|
+
#
|
|
11
|
+
# To use it, add this to your CMakeLists.txt:
|
|
12
|
+
# ```cmake
|
|
13
|
+
# include(${CMAKE_SOURCE_DIR}/../nitrogen/generated/android/NitroFBAnalytics+autolinking.cmake)
|
|
14
|
+
# ```
|
|
15
|
+
|
|
16
|
+
# Define a flag to check if we are building properly
|
|
17
|
+
add_definitions(-DBUILDING_NITROFBANALYTICS_WITH_GENERATED_CMAKE_PROJECT)
|
|
18
|
+
|
|
19
|
+
# Enable Raw Props parsing in react-native (for Nitro Views)
|
|
20
|
+
add_definitions(-DRN_SERIALIZABLE_STATE)
|
|
21
|
+
|
|
22
|
+
# Add all headers that were generated by Nitrogen
|
|
23
|
+
include_directories(
|
|
24
|
+
"../nitrogen/generated/shared/c++"
|
|
25
|
+
"../nitrogen/generated/android/c++"
|
|
26
|
+
"../nitrogen/generated/android/"
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
# Add all .cpp sources that were generated by Nitrogen
|
|
30
|
+
target_sources(
|
|
31
|
+
# CMake project name (Android C++ library name)
|
|
32
|
+
NitroFBAnalytics PRIVATE
|
|
33
|
+
# Autolinking Setup
|
|
34
|
+
../nitrogen/generated/android/NitroFBAnalyticsOnLoad.cpp
|
|
35
|
+
# Shared Nitrogen C++ sources
|
|
36
|
+
../nitrogen/generated/shared/c++/HybridFacebookAnalyticsSpec.cpp
|
|
37
|
+
# Android-specific Nitrogen C++ sources
|
|
38
|
+
../nitrogen/generated/android/c++/JHybridFacebookAnalyticsSpec.cpp
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
# From node_modules/react-native/ReactAndroid/cmake-utils/folly-flags.cmake
|
|
42
|
+
# Used in node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake
|
|
43
|
+
target_compile_definitions(
|
|
44
|
+
NitroFBAnalytics PRIVATE
|
|
45
|
+
-DFOLLY_NO_CONFIG=1
|
|
46
|
+
-DFOLLY_HAVE_CLOCK_GETTIME=1
|
|
47
|
+
-DFOLLY_USE_LIBCPP=1
|
|
48
|
+
-DFOLLY_CFG_NO_COROUTINES=1
|
|
49
|
+
-DFOLLY_MOBILE=1
|
|
50
|
+
-DFOLLY_HAVE_RECVMMSG=1
|
|
51
|
+
-DFOLLY_HAVE_PTHREAD=1
|
|
52
|
+
# Once we target android-23 above, we can comment
|
|
53
|
+
# the following line. NDK uses GNU style stderror_r() after API 23.
|
|
54
|
+
-DFOLLY_HAVE_XSI_STRERROR_R=1
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
# Add all libraries required by the generated specs
|
|
58
|
+
find_package(fbjni REQUIRED) # <-- Used for communication between Java <-> C++
|
|
59
|
+
find_package(ReactAndroid REQUIRED) # <-- Used to set up React Native bindings (e.g. CallInvoker/TurboModule)
|
|
60
|
+
find_package(react-native-nitro-modules REQUIRED) # <-- Used to create all HybridObjects and use the Nitro core library
|
|
61
|
+
|
|
62
|
+
# Link all libraries together
|
|
63
|
+
target_link_libraries(
|
|
64
|
+
NitroFBAnalytics
|
|
65
|
+
fbjni::fbjni # <-- Facebook C++ JNI helpers
|
|
66
|
+
ReactAndroid::jsi # <-- RN: JSI
|
|
67
|
+
react-native-nitro-modules::NitroModules # <-- NitroModules Core :)
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
# Link react-native (different prefab between RN 0.75 and RN 0.76)
|
|
71
|
+
if(ReactAndroid_VERSION_MINOR GREATER_EQUAL 76)
|
|
72
|
+
target_link_libraries(
|
|
73
|
+
NitroFBAnalytics
|
|
74
|
+
ReactAndroid::reactnative # <-- RN: Native Modules umbrella prefab
|
|
75
|
+
)
|
|
76
|
+
else()
|
|
77
|
+
target_link_libraries(
|
|
78
|
+
NitroFBAnalytics
|
|
79
|
+
ReactAndroid::react_nativemodule_core # <-- RN: TurboModules Core
|
|
80
|
+
)
|
|
81
|
+
endif()
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// NitroFBAnalytics+autolinking.gradle
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
/// This is a Gradle file that adds all files generated by Nitrogen
|
|
9
|
+
/// to the current Gradle project.
|
|
10
|
+
///
|
|
11
|
+
/// To use it, add this to your build.gradle:
|
|
12
|
+
/// ```gradle
|
|
13
|
+
/// apply from: '../nitrogen/generated/android/NitroFBAnalytics+autolinking.gradle'
|
|
14
|
+
/// ```
|
|
15
|
+
|
|
16
|
+
logger.warn("[NitroModules] 🔥 NitroFBAnalytics is boosted by nitro!")
|
|
17
|
+
|
|
18
|
+
android {
|
|
19
|
+
sourceSets {
|
|
20
|
+
main {
|
|
21
|
+
java.srcDirs += [
|
|
22
|
+
// Nitrogen files
|
|
23
|
+
"${project.projectDir}/../nitrogen/generated/android/kotlin"
|
|
24
|
+
]
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// NitroFBAnalyticsOnLoad.cpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#ifndef BUILDING_NITROFBANALYTICS_WITH_GENERATED_CMAKE_PROJECT
|
|
9
|
+
#error NitroFBAnalyticsOnLoad.cpp is not being built with the autogenerated CMakeLists.txt project. Is a different CMakeLists.txt building this?
|
|
10
|
+
#endif
|
|
11
|
+
|
|
12
|
+
#include "NitroFBAnalyticsOnLoad.hpp"
|
|
13
|
+
|
|
14
|
+
#include <jni.h>
|
|
15
|
+
#include <fbjni/fbjni.h>
|
|
16
|
+
#include <NitroModules/HybridObjectRegistry.hpp>
|
|
17
|
+
|
|
18
|
+
#include "JHybridFacebookAnalyticsSpec.hpp"
|
|
19
|
+
#include <NitroModules/DefaultConstructableObject.hpp>
|
|
20
|
+
|
|
21
|
+
namespace margelo::nitro::fbanalytics {
|
|
22
|
+
|
|
23
|
+
int initialize(JavaVM* vm) {
|
|
24
|
+
using namespace margelo::nitro;
|
|
25
|
+
using namespace margelo::nitro::fbanalytics;
|
|
26
|
+
using namespace facebook;
|
|
27
|
+
|
|
28
|
+
return facebook::jni::initialize(vm, [] {
|
|
29
|
+
// Register native JNI methods
|
|
30
|
+
margelo::nitro::fbanalytics::JHybridFacebookAnalyticsSpec::registerNatives();
|
|
31
|
+
|
|
32
|
+
// Register Nitro Hybrid Objects
|
|
33
|
+
HybridObjectRegistry::registerHybridObjectConstructor(
|
|
34
|
+
"FacebookAnalytics",
|
|
35
|
+
[]() -> std::shared_ptr<HybridObject> {
|
|
36
|
+
static DefaultConstructableObject<JHybridFacebookAnalyticsSpec::javaobject> object("com/margelo/nitro/com/nitrofbanalytics/HybridFacebookAnalytics");
|
|
37
|
+
auto instance = object.create();
|
|
38
|
+
return instance->cthis()->shared();
|
|
39
|
+
}
|
|
40
|
+
);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
} // namespace margelo::nitro::fbanalytics
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// NitroFBAnalyticsOnLoad.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#include <jni.h>
|
|
9
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
10
|
+
|
|
11
|
+
namespace margelo::nitro::fbanalytics {
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Initializes the native (C++) part of NitroFBAnalytics, and autolinks all Hybrid Objects.
|
|
15
|
+
* Call this in your `JNI_OnLoad` function (probably inside `cpp-adapter.cpp`).
|
|
16
|
+
* Example:
|
|
17
|
+
* ```cpp (cpp-adapter.cpp)
|
|
18
|
+
* JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) {
|
|
19
|
+
* return margelo::nitro::fbanalytics::initialize(vm);
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
int initialize(JavaVM* vm);
|
|
24
|
+
|
|
25
|
+
} // namespace margelo::nitro::fbanalytics
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JHybridFacebookAnalyticsSpec.cpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#include "JHybridFacebookAnalyticsSpec.hpp"
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
#include <string>
|
|
13
|
+
#include <optional>
|
|
14
|
+
#include <NitroModules/Promise.hpp>
|
|
15
|
+
#include <NitroModules/JPromise.hpp>
|
|
16
|
+
#include <unordered_map>
|
|
17
|
+
|
|
18
|
+
namespace margelo::nitro::fbanalytics {
|
|
19
|
+
|
|
20
|
+
jni::local_ref<JHybridFacebookAnalyticsSpec::jhybriddata> JHybridFacebookAnalyticsSpec::initHybrid(jni::alias_ref<jhybridobject> jThis) {
|
|
21
|
+
return makeCxxInstance(jThis);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
void JHybridFacebookAnalyticsSpec::registerNatives() {
|
|
25
|
+
registerHybrid({
|
|
26
|
+
makeNativeMethod("initHybrid", JHybridFacebookAnalyticsSpec::initHybrid),
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
size_t JHybridFacebookAnalyticsSpec::getExternalMemorySize() noexcept {
|
|
31
|
+
static const auto method = javaClassStatic()->getMethod<jlong()>("getMemorySize");
|
|
32
|
+
return method(_javaPart);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
bool JHybridFacebookAnalyticsSpec::equals(const std::shared_ptr<HybridObject>& other) {
|
|
36
|
+
if (auto otherCast = std::dynamic_pointer_cast<JHybridFacebookAnalyticsSpec>(other)) {
|
|
37
|
+
return _javaPart == otherCast->_javaPart;
|
|
38
|
+
}
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
void JHybridFacebookAnalyticsSpec::dispose() noexcept {
|
|
43
|
+
static const auto method = javaClassStatic()->getMethod<void()>("dispose");
|
|
44
|
+
method(_javaPart);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
std::string JHybridFacebookAnalyticsSpec::toString() {
|
|
48
|
+
static const auto method = javaClassStatic()->getMethod<jni::JString()>("toString");
|
|
49
|
+
auto javaString = method(_javaPart);
|
|
50
|
+
return javaString->toStdString();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Properties
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
// Methods
|
|
57
|
+
void JHybridFacebookAnalyticsSpec::logEvent(const std::string& eventName, double valueToSum, const std::unordered_map<std::string, std::string>& params) {
|
|
58
|
+
static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* eventName */, double /* valueToSum */, jni::alias_ref<jni::JMap<jni::JString, jni::JString>> /* params */)>("logEvent");
|
|
59
|
+
method(_javaPart, jni::make_jstring(eventName), valueToSum, [&]() -> jni::local_ref<jni::JMap<jni::JString, jni::JString>> {
|
|
60
|
+
auto __map = jni::JHashMap<jni::JString, jni::JString>::create(params.size());
|
|
61
|
+
for (const auto& __entry : params) {
|
|
62
|
+
__map->put(jni::make_jstring(__entry.first), jni::make_jstring(__entry.second));
|
|
63
|
+
}
|
|
64
|
+
return __map;
|
|
65
|
+
}());
|
|
66
|
+
}
|
|
67
|
+
void JHybridFacebookAnalyticsSpec::logEventWithoutParams(const std::string& eventName, double valueToSum) {
|
|
68
|
+
static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* eventName */, double /* valueToSum */)>("logEventWithoutParams");
|
|
69
|
+
method(_javaPart, jni::make_jstring(eventName), valueToSum);
|
|
70
|
+
}
|
|
71
|
+
void JHybridFacebookAnalyticsSpec::logPurchase(double amount, const std::string& currency, const std::unordered_map<std::string, std::string>& params) {
|
|
72
|
+
static const auto method = javaClassStatic()->getMethod<void(double /* amount */, jni::alias_ref<jni::JString> /* currency */, jni::alias_ref<jni::JMap<jni::JString, jni::JString>> /* params */)>("logPurchase");
|
|
73
|
+
method(_javaPart, amount, jni::make_jstring(currency), [&]() -> jni::local_ref<jni::JMap<jni::JString, jni::JString>> {
|
|
74
|
+
auto __map = jni::JHashMap<jni::JString, jni::JString>::create(params.size());
|
|
75
|
+
for (const auto& __entry : params) {
|
|
76
|
+
__map->put(jni::make_jstring(__entry.first), jni::make_jstring(__entry.second));
|
|
77
|
+
}
|
|
78
|
+
return __map;
|
|
79
|
+
}());
|
|
80
|
+
}
|
|
81
|
+
void JHybridFacebookAnalyticsSpec::logPushNotificationOpen(const std::unordered_map<std::string, std::string>& payload) {
|
|
82
|
+
static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<jni::JMap<jni::JString, jni::JString>> /* payload */)>("logPushNotificationOpen");
|
|
83
|
+
method(_javaPart, [&]() -> jni::local_ref<jni::JMap<jni::JString, jni::JString>> {
|
|
84
|
+
auto __map = jni::JHashMap<jni::JString, jni::JString>::create(payload.size());
|
|
85
|
+
for (const auto& __entry : payload) {
|
|
86
|
+
__map->put(jni::make_jstring(__entry.first), jni::make_jstring(__entry.second));
|
|
87
|
+
}
|
|
88
|
+
return __map;
|
|
89
|
+
}());
|
|
90
|
+
}
|
|
91
|
+
void JHybridFacebookAnalyticsSpec::setUserID(const std::string& userID) {
|
|
92
|
+
static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* userID */)>("setUserID");
|
|
93
|
+
method(_javaPart, jni::make_jstring(userID));
|
|
94
|
+
}
|
|
95
|
+
void JHybridFacebookAnalyticsSpec::clearUserID() {
|
|
96
|
+
static const auto method = javaClassStatic()->getMethod<void()>("clearUserID");
|
|
97
|
+
method(_javaPart);
|
|
98
|
+
}
|
|
99
|
+
std::optional<std::string> JHybridFacebookAnalyticsSpec::getUserID() {
|
|
100
|
+
static const auto method = javaClassStatic()->getMethod<jni::local_ref<jni::JString>()>("getUserID");
|
|
101
|
+
auto __result = method(_javaPart);
|
|
102
|
+
return __result != nullptr ? std::make_optional(__result->toStdString()) : std::nullopt;
|
|
103
|
+
}
|
|
104
|
+
void JHybridFacebookAnalyticsSpec::setUserData(const std::optional<std::string>& email, const std::optional<std::string>& firstName, const std::optional<std::string>& lastName, const std::optional<std::string>& phone, const std::optional<std::string>& dateOfBirth, const std::optional<std::string>& gender, const std::optional<std::string>& city, const std::optional<std::string>& state, const std::optional<std::string>& zip, const std::optional<std::string>& country) {
|
|
105
|
+
static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* email */, jni::alias_ref<jni::JString> /* firstName */, jni::alias_ref<jni::JString> /* lastName */, jni::alias_ref<jni::JString> /* phone */, jni::alias_ref<jni::JString> /* dateOfBirth */, jni::alias_ref<jni::JString> /* gender */, jni::alias_ref<jni::JString> /* city */, jni::alias_ref<jni::JString> /* state */, jni::alias_ref<jni::JString> /* zip */, jni::alias_ref<jni::JString> /* country */)>("setUserData");
|
|
106
|
+
method(_javaPart, email.has_value() ? jni::make_jstring(email.value()) : nullptr, firstName.has_value() ? jni::make_jstring(firstName.value()) : nullptr, lastName.has_value() ? jni::make_jstring(lastName.value()) : nullptr, phone.has_value() ? jni::make_jstring(phone.value()) : nullptr, dateOfBirth.has_value() ? jni::make_jstring(dateOfBirth.value()) : nullptr, gender.has_value() ? jni::make_jstring(gender.value()) : nullptr, city.has_value() ? jni::make_jstring(city.value()) : nullptr, state.has_value() ? jni::make_jstring(state.value()) : nullptr, zip.has_value() ? jni::make_jstring(zip.value()) : nullptr, country.has_value() ? jni::make_jstring(country.value()) : nullptr);
|
|
107
|
+
}
|
|
108
|
+
std::shared_ptr<Promise<std::optional<std::string>>> JHybridFacebookAnalyticsSpec::getAnonymousID() {
|
|
109
|
+
static const auto method = javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>()>("getAnonymousID");
|
|
110
|
+
auto __result = method(_javaPart);
|
|
111
|
+
return [&]() {
|
|
112
|
+
auto __promise = Promise<std::optional<std::string>>::create();
|
|
113
|
+
__result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
|
|
114
|
+
auto __result = jni::static_ref_cast<jni::JString>(__boxedResult);
|
|
115
|
+
__promise->resolve(__result != nullptr ? std::make_optional(__result->toStdString()) : std::nullopt);
|
|
116
|
+
});
|
|
117
|
+
__result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
|
|
118
|
+
jni::JniException __jniError(__throwable);
|
|
119
|
+
__promise->reject(std::make_exception_ptr(__jniError));
|
|
120
|
+
});
|
|
121
|
+
return __promise;
|
|
122
|
+
}();
|
|
123
|
+
}
|
|
124
|
+
std::shared_ptr<Promise<std::optional<std::string>>> JHybridFacebookAnalyticsSpec::getAdvertiserID() {
|
|
125
|
+
static const auto method = javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>()>("getAdvertiserID");
|
|
126
|
+
auto __result = method(_javaPart);
|
|
127
|
+
return [&]() {
|
|
128
|
+
auto __promise = Promise<std::optional<std::string>>::create();
|
|
129
|
+
__result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
|
|
130
|
+
auto __result = jni::static_ref_cast<jni::JString>(__boxedResult);
|
|
131
|
+
__promise->resolve(__result != nullptr ? std::make_optional(__result->toStdString()) : std::nullopt);
|
|
132
|
+
});
|
|
133
|
+
__result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
|
|
134
|
+
jni::JniException __jniError(__throwable);
|
|
135
|
+
__promise->reject(std::make_exception_ptr(__jniError));
|
|
136
|
+
});
|
|
137
|
+
return __promise;
|
|
138
|
+
}();
|
|
139
|
+
}
|
|
140
|
+
void JHybridFacebookAnalyticsSpec::setFlushBehavior(const std::string& flushBehavior) {
|
|
141
|
+
static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* flushBehavior */)>("setFlushBehavior");
|
|
142
|
+
method(_javaPart, jni::make_jstring(flushBehavior));
|
|
143
|
+
}
|
|
144
|
+
void JHybridFacebookAnalyticsSpec::flush() {
|
|
145
|
+
static const auto method = javaClassStatic()->getMethod<void()>("flush");
|
|
146
|
+
method(_javaPart);
|
|
147
|
+
}
|
|
148
|
+
void JHybridFacebookAnalyticsSpec::setPushNotificationsDeviceToken(const std::string& token) {
|
|
149
|
+
static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* token */)>("setPushNotificationsDeviceToken");
|
|
150
|
+
method(_javaPart, jni::make_jstring(token));
|
|
151
|
+
}
|
|
152
|
+
void JHybridFacebookAnalyticsSpec::setPushNotificationsRegistrationId(const std::string& registrationId) {
|
|
153
|
+
static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* registrationId */)>("setPushNotificationsRegistrationId");
|
|
154
|
+
method(_javaPart, jni::make_jstring(registrationId));
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
} // namespace margelo::nitro::fbanalytics
|