onetarget-react-native
v4.0.9
Published
test
Downloads
94
Readme
onetarget-react-native
Onetarget Wrapper Native SDK
Installation
npm install onetarget-react-native
Usage
import { OneTargetAnalytics } from 'onetarget-react-native';
// ...
1. Initialize
OneTargetAnalytics.initialize("[your_workspace_id]", "[your_flavor]", "[your_app_push_id]"); // flavor : dev, stg, prod
2. Tracking Event
function onAddtoCart() {
let eventName = "add_to_cart"; // Event Name
let identify = { "ext_identify": ext_identify};
let eventData = { "ecommerce.trip_passengers_children": "1", "ecommerce.items.0.item_variant": "Eco", "ecommerce.trip_return_date": "2022-09-23", "ecommerce.items.0.flight_time": "06:20-08:30", "ecommerce.trip_start_date": "2022-09-23", "ecommerce.trip_passengers_adult": "2", "ecommerce.trip_to": "SGN", "platform": "APP", "ecommerce.items.0.index": "1", "ecommerce.trip_route": "SGN-HN", "ecommerce.trip_passengers_infant": "0", "ecommerce.currency": "VND", "ecommerce.items.0.item_category": "FareOption", "ecommerce.items.0.quantity": "1", "ecommerce.trip_from": "HAN", "ecommerce.trip_passengers": "1", "ecommerce.items.0.flight_from": "HAN", "ecommerce.items.0.price": "39.000đ", "ecommerce.items.0.flight_date": "2022-09-23", "ecommerce.items.0.item_id": "VJ197", "ecommerce.items.0.item_list_id": "Outbound:HAN:SGN", "ecommerce.trip_type": "roundTrip", "ecommerce.items.0.flight_to": "SGN", "ecommerce.items.0.item_name": "Flight:HAN:SGN" };
var profiles = [{ "ext_identify": ext_identify }];
OneTargetAnalytics.trackEvent(
identify,
eventName,
eventData,
profiles
);
}
3. Add a Notification Service Extension
The OneTargetNotificationServiceExtension allows your application to receive rich notifications with images and/or buttons, and to report analytics about which notifications users receive.
- In Xcode Select File > New > Target...
- Select Notification Service Extension then press Next.
- Enter the product name as OneTargetNotificationServiceExtension and press Finish. Do not press "Activate" on the dialog shown after this.
- At OneTargetNotificationServiceExtension Link Library : OneTargetMobileSDK.xcframework, OneSignal.xcframework from Pods frameworks.
- In the OneTargetNotificationServiceExtension directory > NotificationService.m or NotificationService.swift file, replace the whole file contents with the code below:
import OneTargetMobileSDK
class NotificationService: UNNotificationServiceExtension {
var contentHandler: ((UNNotificationContent) -> Void)?
var bestAttemptContent: UNMutableNotificationContent?
var receivedRequest: UNNotificationRequest!
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
self.receivedRequest = request
self.contentHandler = contentHandler
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
if let bestAttemptContent = bestAttemptContent {
// Modify the notification content here...
bestAttemptContent.title = "\(bestAttemptContent.title) [modified]"
_ = OneTargetAnalytics.didReceiveNotificationExtensionRequest(self.receivedRequest, with: bestAttemptContent, withContentHandler: self.contentHandler)
}
}
override func serviceExtensionTimeWillExpire() {
// Called just before the extension will be terminated by the system.
// Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
if let contentHandler = contentHandler, let bestAttemptContent = bestAttemptContent {
_ = OneTargetAnalytics.serviceExtensionTimeWillExpireRequest(self.receivedRequest, with: self.bestAttemptContent)
contentHandler(bestAttemptContent)
}
}
}
4. Add App Group
- Add "Sign In & Capabilities" add App Groups for All Target "Your Projects and OneTargetNotificationServiceExtension.
Contributing
See the contributing guide to learn how to contribute to the repository and the development workflow.
License
MIT
Made with create-react-native-library