# onetarget-react-native

> test

Latest version **4.0.9** (published 2022-11-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install onetarget-react-native
pnpm add onetarget-react-native
yarn add onetarget-react-native
bun add onetarget-react-native
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.9 |
| Published | 2022-11-21 |
| First published | 2022-08-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 122.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | baocq@galaxy.one |
| Maintainers | baocq.io, g1-onetarget, baocq |
| Keywords | react-native, ios, android |

## Links

- npm: https://www.npmjs.com/package/onetarget-react-native
- Repository: https://gitlab.com/g1-data/onetarget-react-native
- Homepage: https://gitlab.com/g1-data/onetarget-react-native#readme
- Issues: https://gitlab.com/g1-data/onetarget-react-native/issues
- npm.io page: https://npm.io/package/onetarget-react-native

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 4.0.9 (latest) — 2022-11-21
- 4.0.5 — 2022-11-15
- 4.0.4 — 2022-11-14
- 4.0.3 — 2022-11-14
- 4.0.1 — 2022-11-02
- 4.0.0 — 2022-11-02
- 3.3.4 — 2022-10-19
- 3.3.3 — 2022-10-19
- 3.3.2 — 2022-10-18
- 3.3.1 — 2022-10-17
- 3.3.0 — 2022-10-11
- 3.2.4 — 2022-09-30
- 3.2.3 — 2022-09-29
- 3.2.2 — 2022-09-29
- 3.2.0 — 2022-09-28
- … 26 more at https://npm.io/package/onetarget-react-native/versions

## README

# onetarget-react-native
Onetarget Wrapper Native SDK
## Installation

```sh
npm install onetarget-react-native
```

## Usage

```import
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](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.

## License

MIT

---

Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)

---
_Source: https://npm.io/package/onetarget-react-native · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
