1.1.34 • Published 3 years ago

react-native-rn-vizury-logger v1.1.34

Weekly downloads
76
License
MIT
Repository
bitbucket
Last release
3 years ago

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

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

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


#import "RnVizuryLogger.h"`

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

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

Swift


#import RnVizuryLogger

Update your AppDelegate

class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate

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

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

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

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

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

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

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

alt text

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

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

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

  // didReceiveLocalNotification Code Here

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

    [application registerForRemoteNotifications];

}

// iOS 7 or iOS 6

- (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
} 
- (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];
    }
}
#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();
}
- (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

    .....
        <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

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

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

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

1.1.34

3 years ago

1.1.33

3 years ago

1.1.32

3 years ago

1.1.31

3 years ago

1.1.30

3 years ago

1.1.29

3 years ago

1.1.28

3 years ago

1.1.27

3 years ago

1.1.26

3 years ago

1.1.25

3 years ago

1.1.24

3 years ago

1.1.23

3 years ago

1.1.22

3 years ago

1.1.21

3 years ago

1.1.20

4 years ago

1.1.19

4 years ago

1.1.18

4 years ago

1.1.16

4 years ago

1.1.17

4 years ago

1.1.15

4 years ago

1.1.14

4 years ago

1.1.13

4 years ago

1.1.12

4 years ago

1.1.9

4 years ago

1.1.11

4 years ago

1.1.10

4 years ago

1.1.8

4 years ago

1.1.7

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago

0.0.62

4 years ago

0.0.63

4 years ago

0.0.65

4 years ago

0.0.61

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago