# react-native-rn-vizury-logger-test

> TODO

Latest version **1.1.29** (published 2021-01-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-native-rn-vizury-logger-test
pnpm add react-native-rn-vizury-logger-test
yarn add react-native-rn-vizury-logger-test
bun add react-native-rn-vizury-logger-test
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.29 |
| Published | 2021-01-21 |
| First published | 2021-01-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 315.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Your Name |
| Maintainers | ayon.affle |
| Keywords | react-native |

## Links

- npm: https://www.npmjs.com/package/react-native-rn-vizury-logger-test
- Repository: https://bitbucket.org/vizury/vizury-react-native/src/master/
- Homepage: https://bitbucket.org/vizury/vizury-react-native/src/master/README.md
- Issues: https://bitbucket.org/vizury/vizury-react-native/src/master/
- npm.io page: https://npm.io/package/react-native-rn-vizury-logger-test

## Recent versions

- 1.1.29 (latest) — 2021-01-21
- 1.1.28 — 2021-01-15
- 1.1.27 — 2021-01-15
- 1.1.26 — 2021-01-07
- 1.1.25 — 2021-01-05

## README

# VizuryEventLogger React Native

Vizury is a commerce marketing platform and its personalized retargeting stack is used by digital companies to grow marketing ROI and enhance transactions.

## Summary

This is npm package to integrate Vizury SDK in react-native. The SDK supports iOS12 and above. 

Open terminal and go to project folder and run below commands


## Install via NPM

`$ npm install react-native-rn-vizury-logger`

### Mostly automatic installation

`$ react-native link react-native-rn-vizury-logger`



## Usage
```javascript
import RnVizuryLogger from 'react-native-rn-vizury-logger';

//Event Logging

 if (Platform.OS === 'ios'){
      RnVizuryLogger.addEvent({ param: 'param1', param2: "param2", param4: "param4" }, 'Vizuri Test')

    }else{
      var attributesMap = {};
      attributesMap["pid"] = "AFGEMSBBLL";
      attributesMap["quantity"] = "1";
      attributesMap["price"] = "876";
      attributesMap["category"] = "clothing";
      var sendingMap = {};
      sendingMap["attributes"] = attributesMap;
      RnVizuryLogger.addEvent(sendingMap, 'product page');

    }

```


## iOS Integration



First open Pod file in your iOS app and add these lines 

```javascript
use_frameworks!
pod 'Firebase/Messaging'
```

Then open terminal and go to project folder then do following steps to install pod file



```
$ cd ios
$ pod install
```

If you find any issue in pod install please try with ```pod install --repo-update```.

## Vizury SDK Initialization

In your AppDelegate file import the VizuryEventLogger

#### Objective-C
----
```objc
#import "RnVizuryLogger.h"`
```

Add the following in `didFinishLaunchingWithOptions` method of AppDelegate to initialize the SDK

```objc
[RnVizuryLogger initializeEventLoggerInApplication:(UIApplication*)application
                            WithPackageId:(NSString *)packageId
                            ServerURL:(NSString *)serverURL
                            WithCachingEnabled:(BOOL) caching
                            AndWithFCMEnabled:(BOOL) isFCMEnabled];
```

#### Swift
---- 
```objc
#import RnVizuryLogger
```

Update your AppDelegate

```swift
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate
```

Add the following in `didFinishLaunchingWithOptions` method of AppDelegate to initialize the SDK

```objc
RnVizuryLogger.initializeEventLogger(in: application,
            withPackageId: packageId, 
            serverURL: serverUrl,
            withCachingEnabled: caching, 
            AndWithFCMEnabled: isFCMEnabled)
```

```
Where 
  packageId     : packageId obtained from vizury
  serverURL     : serverURL obtained from vizury
  caching       : pass true if your app supports offline usage and you want to send user behaviour data 
                  to vizury while he was offline. Pass false otherwise
  isFCMEnabled  : true/false depending on if you want to use vizury for push
Thats it!! SDK is successfully integrated and initialized in the project, and ready to use.
```


### Push Notifications
For sending push notifications we are using GCM-APNS interface. For this you need to configure the App for push notifications in Apple Developer Member Center and get a configuration file from google.

Configuring Apple Developer Settings
To enable sending Push Notifications through APNs, you need

a) Create the authentication key.

b) Create an App ID

c) Provisioning profile for that App ID.

You can create them in the Apple Developer Member Center by following these steps

Configuring project for FCM
Set up CocoaPods dependencies
If you don't have an Xcode project yet, create one now
Create a Podfile if you don't have one
$ cd your-project directory
$ pod init
Add the Firebase/Messaging pod
pod 'Firebase/Messaging'
Install the pods and open the .xcworkspace file to see the project in Xcode
$ pod install
$ open your-project.xcworkspace
Enabling FCM
Create a Firebase project in the Firebase console if you don't already have one. Enter the Project-Name.

![alt text](https://bytebucket.org/vizury/vizury-ios-sdk/raw/a311dc1a06a82b928939d6a2e81336c576f82a43/resources/firebase1.png?raw=true)



Click on iOS option and in the next screen add the iOS Bundle Id. The iOS Bundle Id should be same as your apps bundle identifier. You can download the GoogleService-Info.plist file in the next step.


![alt text](https://bytebucket.org/vizury/vizury-ios-sdk/raw/a311dc1a06a82b928939d6a2e81336c576f82a43/resources/firebase3.png?raw=true)

Note : The GoogleService-Info.plist file that you have downloaded will have certain settings like IS_ADS_ENABLED, IS_SIGNIN_ENABLED set as YES. You have to add 


correspinding pod dependencies for the same or you can turn them off if you are not using them
Next click on the Settings icon option of the created project.

![alt text](https://bytebucket.org/vizury/vizury-ios-sdk/raw/a311dc1a06a82b928939d6a2e81336c576f82a43/resources/firebase3.png?raw=true)

Click on Cloud Messaging tab and upload APNs Authentication Key (.p8 format). Also note down the the Server key as this will be required later during the integration. You can also upload APNs certificaties but configuration with auth keys is recommended as they are the more current method for sending notifications to iOS


![alt text](https://bytebucket.org/vizury/vizury-ios-sdk/raw/a311dc1a06a82b928939d6a2e81336c576f82a43/resources/firebase4.png?raw=true)

While uploading APNs Authentication Key (.p8 format) you need to enter the Key Id and Team Id. 1. 'Key ID' is the id of the authentication key you created in Apple developer console under Certificates, Identifiers & Profiles -> Keys -> Select the particular certificate


![alt text](https://bytebucket.org/vizury/vizury-ios-sdk/raw/a311dc1a06a82b928939d6a2e81336c576f82a43/resources/keyID.png?raw=true)


'Team ID' is the Team Member ID in Apple developer console under Membership -> Membership Details



![alt text](https://bytebucket.org/vizury/vizury-ios-sdk/raw/a311dc1a06a82b928939d6a2e81336c576f82a43/resources/teamID.png?raw=true)

### Configuring Application

* Drag the GoogleService-Info.plist file you just downloaded into the root of your Xcode project and add it to all targets
* Register for Push notifications inside `didFinishLaunchingWithOptions` method of you `AppDelegate`



 
Drag the GoogleService-Info.plist file you just downloaded into the root of your Xcode project and add it to all targets
Register for Push notifications inside didFinishLaunchingWithOptions method of you AppDelegate.m

```objc
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_7_1) {
    // iOS 7.1 or earlier. Disable the deprecation warnings.
    #pragma clang diagnostic push
    #pragma clang diagnostic ignored "-Wdeprecated-declarations"
    UIRemoteNotificationType allNotificationTypes =
    (UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge);
    [application registerForRemoteNotificationTypes:allNotificationTypes];
    #pragma clang diagnostic pop
} else {
    // iOS 8 or later
    // [START register_for_notifications]
    if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_9_x_Max) {
        #pragma clang diagnostic push
        #pragma clang diagnostic ignored "-Wdeprecated-declarations"
        UIUserNotificationType allNotificationTypes =
        (UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge);
        UIUserNotificationSettings *settings =
        [UIUserNotificationSettings settingsForTypes:allNotificationTypes categories:nil];
        [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
    } else {
        // iOS 10 or later
        #if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
        // For iOS 10 display notification (sent via APNS)
        [UNUserNotificationCenter currentNotificationCenter].delegate = self;
        UNAuthorizationOptions authOptions =
        UNAuthorizationOptionAlert | UNAuthorizationOptionSound | UNAuthorizationOptionBadge;
        [[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:authOptions completionHandler:^(BOOL granted, NSError * _Nullable error) {
        }];
        #endif
    }
    
    [[UIApplication sharedApplication] registerForRemoteNotifications];
  
  }
```


### Getting Notification from FCM


```objc
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {

  // didReceiveLocalNotification Code Here

}
```

```objc
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {

    [application registerForRemoteNotifications];

}
```

`// iOS 7 or iOS 6`
```objc
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    NSString *token = [[deviceToken description] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"<>"]];
    token = [token stringByReplacingOccurrencesOfString:@" " withString:@""];
  NSLog(@"token %@",token);
  [RnVizuryLogger passAPNSToken:deviceToken];
    // Send token to server
} 
```

```objc
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
[RnVizuryLogger didReceiveRemoteNotificationInApplication:application withUserInfo:userInfo];

    if(application.applicationState == UIApplicationStateInactive) {
        NSLog(@"Appilication Inactive - the user has tapped in the notification when app was closed or in background");
        [self customPushHandler:userInfo];
    }
}
```
```objc
#if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
// Handle incoming notification messages while app is in the foreground.
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
            willPresentNotification:(UNNotification *)notification
            withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
    NSDictionary *userInfo = notification.request.content.userInfo;
    NSLog(@"%@", userInfo);
    // Change this to your preferred presentation option
    completionHandler(UNNotificationPresentationOptionNone);
}

// Handle notification messages after display notification is tapped by the user.
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
                didReceiveNotificationResponse:(UNNotificationResponse *)response
                withCompletionHandler:(void (^)(void))completionHandler {
    NSDictionary *userInfo = response.notification.request.content.userInfo;
    [RnVizuryLogger didReceiveResponseWithUserInfo:userInfo];
    
    // Print full message.
    NSLog(@"%@", userInfo);
    completionHandler();
}
```

```objc
- (void) customPushHandler:(NSDictionary *)notification {
    if (notification !=nil && [notification objectForKey:@"deeplink"] != nil) {
        NSString* deeplink = [notification objectForKey:@"deeplink"];
        NSLog(@"%@",deeplink);
        // Here based on the deeplink you can open specific screens that's part of your app
    }
}
```

## Android Integration


#### Vizury SDK Initialization

In your `android/app/src/main/AndroidManifest.xml`

```xml
    .....
        <meta-data
            android:name="Vizury.VRM_ID"
            android:value="{PACKAGE_ID}" />
        <meta-data
            android:name="Vizury.SERVER_URL"
            android:value="{SERVER_URL}" />
        <meta-data
            android:name="Vizury.DEBUG_MODE"
            android:value="{true/false}" /> 
        <meta-data
            android:name="Vizury.NOTIFICATION_ICON"
            android:resource="@mipmap/ic_launcher" />
        <meta-data
            android:name="Vizury.NOTIFICATION_ICON_SMALL"
            android:resource="@mipmap/ic_launcher" />
        <service
            android:name="com.vizury.mobile.Push.VizFirebaseMessagingService">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT"/>
            </intent-filter>
        </service>
        <service
            android:name="com.vizury.mobile.Push.VizIntentService"
            android:exported="false">
        </service>
    .....
```

In your `android/app/build.gradle`

```gradle
dependencies {
  ...
  implementation 'com.google.firebase:firebase-messaging:17.3.4'
  implementation 'com.android.support.constraint:constraint-layout:1.1.3'
  ...

  apply plugin: 'com.google.gms.google-services'
}
```

In your `android/build.gradle`

```gradle
buildscript {
    ...
    dependencies {
        ...
        classpath 'com.google.gms:google-services:4.2.0'
        ...
    }
}
```

Then put your `google-services.json` in `android/app/`.

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