4.0.9 • Published 1 year ago

onetarget-react-native v4.0.9

Weekly downloads
-
License
MIT
Repository
gitlab
Last release
1 year ago

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

4.0.9

1 year ago

3.3.1

2 years ago

3.3.0

2 years ago

3.3.4

2 years ago

3.3.3

2 years ago

3.3.2

2 years ago

4.0.5

1 year ago

4.0.4

1 year ago

4.0.1

2 years ago

4.0.0

2 years ago

4.0.3

1 year ago

1.2.0

2 years ago

1.5.10

2 years ago

1.5.12

2 years ago

1.5.11

2 years ago

1.5.14

2 years ago

1.5.13

2 years ago

1.5.16

2 years ago

1.5.15

2 years ago

1.5.18

2 years ago

1.5.17

2 years ago

1.5.19

2 years ago

3.2.2

2 years ago

3.2.0

2 years ago

3.1.0

2 years ago

3.2.4

2 years ago

3.2.3

2 years ago

3.0.0

2 years ago

1.5.21

2 years ago

1.5.9

2 years ago

1.5.20

2 years ago

1.5.8

2 years ago

1.5.23

2 years ago

1.5.7

2 years ago

1.5.22

2 years ago

1.5.24

2 years ago

1.5.6

2 years ago

1.5.5

2 years ago

1.5.3

2 years ago

1.5.2

2 years ago

1.5.0

2 years ago