Neonatal Penguin March

    @blueconic/blueconic-react-native

    2.0.0 • Public • Published

    BlueConic SDK for React Native

    Getting started

    $ npm install @blueconic/blueconic-react-native --save

    $ react-native link @blueconic/blueconic-react-native

    Usage

    Before you start implementing the SDK, use the following steps to set up your environment:

    React Native

    Run the following command in your React Native project's root folder

    $ npm install @blueconic/blueconic-react-native

    Or include it to your React Native project's package.json 

    {
    "react": "16.8.6",
    "react-native": "0.60.4",
    "@blueconic/blueconic-react-native": "^2.0.0"
    }
    

       

    iOS implementation of the React Native App

    1. Add the .xcodeproj file of the BlueConicClient library

    • In Xcode, add the .xcodeproj file of the BlueConicClient library to the Libraries group of the project, you can find the BlueConicClient.xcodeproj in your app's node_modules in. To do this, drag and drop the .xcodeproj file to the Libraries group in Xcode.
    node_modules/@blueconic/blueconic-react-native/ios
    
    •  The .xcodeproj will include a Product folder, make sure the libBlueConicClient.a library is added to the Link Binary with Libraries section of the Build Phases of the app's target
    • The package is dependent on react-native. It searches for the react-native headers both in your project’s node modules/react-native/React directory, as well as in ./ios/Pods/Headers/Public in case react-native is used through CocoaPods. If the react-native headers are saved elsewhere, add the correct path to the Header Search Paths Build Setting of the BlueConicClient target.

    2. Add the configuration key for BlueConic:

     Locate your app's Information Property List file under "Supporting Files".  Select -Info.plist and add a new row by right clicking the top row and selecting "Add row". Set the following key name:

    bc_server_url
    

     Double-click the value field and enter the URL for the hostname of your BlueConic server. For example:

     http://example.blueconic.net
    

    3. Locate your app's Information Property List file under "Supporting Files".

     Select <project>-Info.plist and add a new row by right clicking the top row and selecting "Add row". Set the following key name:

     URL types
    

     This creates an array which contains more property rows. Open "URL types" by clicking the triangle icon in front of the name to display the rows. Right click "Item 0" and select "Add row". You can also add a new item, and add the new row within that item. Set the following key name:

     URL Schemes
    

     This creates another array. Add a new row to this array's "Item 0" and enter your apps "Bundle Identifier", for example:

     com.blueconic.testApp
    

     

    4. Optionally, add a debug key for BlueConic:

     Locate your app's Information Property List file under "Supporting Files".  Select -Info.plist and add a new row by right clicking the top row and selecting "Add row". Set the following key name:

    bc_debug
    

     Click the type and select 'Boolean'. Set the value to "YES" if you want to receive debug logs from the BlueConic SDK. Adding a debug key is optional; if you do not want to receive debug logs from the SDK, you do not need to add it.

    5. Import BlueConic:

     The BlueConic SDK for iOS enables you to set and retrieve profile property values for a BlueConic profile and enables interactions specific to this BlueConic profile. These methods can be used anywhere in the app. Make sure that you import the framework and get the instance before using the BlueConicClient methods:

    // Swift:
     import BlueConicClient
     
     let client = BlueConicClient.getInstance(self)
     
     // Objective C:
     #import <BlueConicClient/BlueConicClient-swift.h>
    
     BlueConicClient *client = [BlueConicClient getInstance:self]; 
     ** Make sure that you provide the current ViewController as argument when invoking getInstance. If no ViewController is available, pass an empty ViewController.
     After you have added the URL Scheme value, select the AppDelegate class and add the following method to enable simulator functionality:
     
     // Swift: in the AppDelegate.swift file
     func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] ) -> Bool {    BlueConicClient.getInstance(nil).setURL(url)    
     return true
     }
     
     // Objective-C: in the AppDelegate.m file
     - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
     [[BlueConicClient getInstance:nil] setURL:url];
     return YES;
     }
    

     

     Android implementation of the React Native App

    1. Add the Android SDK blueconic-lib-.aar to your app project as gradle module

    • Create blueconic directory in your projects' in the android root directory
    • Add build.gradle file with these contents:
    configurations.maybeCreate("default")
    artifacts.add("default", file('blueconic-lib-<version>.aar'))
    

    Add the .aar file to the 'blueconic' directory, alongside the build.gradle. You now have a gradle module called 'blueconic' which can be used in your app as well as in the BlueConic react-native NPM module.

    2. Include the React Native project in the settings.gradle

    Append the following lines to the android/settings.gradle file.  

    include ':blueconic'
    include ':blueconic_blueconic-react-native'
    project(':blueconic_blueconic-react-native').projectDir = new File(rootProject.projectDir,
            '../node_modules/@blueconic/blueconic-react-native/android')
    

    This loads both the BlueConic React Native library as the BlueConic Android SDK.

    3. (Optionally) Set "allow backup"-option to true in the AndroidManifest.xml

    It could be that the IDE requires to override the "allowBackup" options in order to build Add/ change this option in the AndroidManifest.xml

    android:allowBackup="true"
    

     

    4. Add permissions to the AndroidManifest.xml:

     <uses-permission android:name="android.permission.INTERNET" />
     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    

     

    5. Add intent filters to the AndroidManifest.xml for connecting to the simulator:

    Configure your appId at the android:scheme attribute in the code fragment below. For example "com.test.testapp".

     <activity android:name=".MainActivity" android:label="@string/app_name">
     <intent-filter>
     <action android:name="android.intent.action.MAIN"/>
     <category android:name="android.intent.category.LAUNCHER"/>
     </intent-filter>
     <!-- Filter added for connecting to the simulator through mail .-->
     <intent-filter>
     <action android:name="android.intent.action.SEND"/>
     <category android:name="android.intent.category.DEFAULT"/>
     <data android:mimeType="text/plain"/>
     </intent-filter>
     <!-- Filter added for connecting to the simulator through a QR scan. -->
     <intent-filter>
     <action android:name="android.intent.action.VIEW"/>
     <category android:name="android.intent.category.DEFAULT"/>
     <category android:name="android.intent.category.BROWSABLE"/>
     <data android:scheme="<Your appId>"/>
     </intent-filter>
     </activity>
    

    6. Add the configuration file for BlueConic:

     Create a file named blueconic_configuration.xml in /res/values/:

    <?xml version="1.0" encoding="utf-8"?>
     <resources>
     <string name="bc_server_url">[BlueConic server url]</string>
     </resources>
    

     Replace [BlueConic server url] with the protocol and hostname of the BlueConic server. For example "http://example.blueconic.net":

     <?xml version="1.0" encoding="utf-8"?>
     <resources>
     <string name="bc_server_url">http://example.blueconic.net</string>
     </resources>
    

    7. Optionally, enable debug mode:

     Add the following node to the configuration file  ``` true

     
     Example configuration file:
     ```
    <?xml version="1.0" encoding="utf-8"?>
     <resources>
     <string name="bc_server_url">http://example.blueconic.net</string>
     <bool name="bc_debug">true</bool>
     </resources>
    

     

    Using the BlueConicClient SDK in React Native apps:

    1. Import NativeModules in the app

     Import the BlueConicClient module within your app

    // React Native: in the Example.js file
     import {
       NativeModules
     } from "react-native";
    
     const {BlueConicClient} = NativeModules;
    

    2. Create a page view event each time the user switches screens 

     To keep track of every page viewed in the app, you are able to do so by creating a page view event. Make sure that a unique screen name is passed in the call. The screen name can be used in listener rules or to restrict interactions to specific screens. 

     // React Native: in the Example.js file
     // Simple screen names, like 'main' pages
     BlueConicClient.registerPageView("main");
     
     // Unique screen names, e.g. per article
     BlueConicClient.registerPageView("news/article/" + UID);
    

    3. Retrieving and storing profile properties:

     The BlueConic SDK for React native enables you to set and retrieve profile property values for a BlueConic profile. These methods can be used anywhere in the app. The following example counts the number of times a page has been opened and stores this number in the BlueConic profile:

     // React native: in the ExampleScreen.js file
     import React, { Component } from 'react';
     import {
       Text,
       View,
       NativeModules
     } from 'react-native';
     const {BlueConicClient} = NativeModules;
     const PROPERTY_ID = "pageCount";
     
     export default class ExampleScreen extends Component {
       constructor() {
         super();
         this.state {
           pageCount: 0
         };
         this.updatePageCount();
       }
       updatePageCount = async() => {
         const getProfileValueResult = await BlueConicClient.getProfileValue(PROPERTY_ID);
         let pageCountValue = parseInt(getProfileResult) ?? 0;
         BlueConicClient.setProfileValue(PROPERTY_ID, ++pageCountValue);
     
         this.setState({
           pageCount: pageCountValue
         });
       }
     }
    

    4. Register events:

     Calls to register an event can be done in the onLoad of a custom developed mobile Plugin. The code fragment shows how to trigger a click event. Possible events are: "VIEW", "CLICK" and "CONVERSION"

     // React native: in the ExamplePlugin.js file
     
     // Register Dialogue events
     BlueConicClient.registerDialogueEvent("VIEW", this.interactionId);
     BlueConicClient.registerDialogueEvent("CLICK", this.interactionId);
     BlueConicClient.registerDialogueEvent("CONVERSION", this.interactionId);
     
     // Register events through 'createEvent'
     BlueConicClient.createEvent("VIEW", {
     "interactionId": this.interactionId
     }
    

     

    Configuring BlueConic

     This section describes how to add the channel for your mobile application to your BlueConic universe as well as how to define your custom profile properties so that you can use them in BlueConic segments.   ### Add the mobile channel to your universe  Before you can start measuring activity in your mobile applications and maintain values in visitor profile properties, the channel for your mobile application must be added to a domain in your BlueConic universe. The very first time that you start your application, BlueConic will detect it. It must then be added as a channel of the type "Mobile App" in a domain. See Managing channels for complete information.   ### Custom profile properties  If you want your mobile application to be able to add custom properties to visitor profiles and use them in BlueConic segments, those custom profile properties must be added to your plugin. For complete information on writing a custom plugin, see Plugin Types. For information about adding custom profile properties, see profile properties.   ## BlueConicClient Methods  Implementation of the BlueConic client, handling profile retrieval and storage. This may be from cache, persistent storage on the client or direct requests to the BlueConic server.

     import {
     NativeModules
     } from "react-native";
     const {BlueConicClient} = NativeModules;
    

     getProfileId() -> String

     Returns the ID of the BlueConic Profile.

     // with promise:
     const profileId = await BlueConicClient.getProfileId();
     
     // with callback:
     BlueConicClient.getProfileIdWithCallback(profileId => {
     
     });
    

     Return Value The ID of the BlueConic profile

      getProfileValue(property: String) -> String

     Returns the first value for a given profile property.

     // with promise:
     const hobby = await BlueConicClient.getProfileValue("hobby");
     
     // with callback:
     BlueConicClient.getProfileValueWithCallback("hobby", hobby => {
     
     });
    

     Parameter property The profile property to get the values for.  

     Return Value  The first value  

    getProfileValues(property: String) -> String[]

       Return the values for a given profile property.  

     // with promise:
     const hobbies = await BlueConicClient.getProfileValues("hobbies");
     
     // with callback:
     BlueConicClient.getProfileValuesWithCallback("hobbies", hobbies => {
     
     });
    

     Parameter property  The profile property to get the values for.  

     Return Value A collection containing the values.      

    addProfileValue(property: String, value: String)

     Adds a single property value to the profile. If there are already values for a property the new value will be added. Values for a property need to be unique; passing the same value multiple times will have no effect.  

     BlueConicClient.addProfileValue("hobbies", "tennis");
    

    Parameter property The profile property to add the values for.

    Parameter value The property value to add to the profile.

       

     addProfileValues(property: String, values: String[]) 

     Adds property values to the profile. The values from the collection are added to the profile. If there are already values for a property the new values will be added. Values for a property need to be unique; passing the same values multiple times will have no effect.  

     BlueConicClient.addProfileValues("hobbies", ["tennis", "soccer"]);
    

    Parameter property The profile property to add the values for.

    Parameter values The property values to add to the profile.

       

     setProfileValue(name: String, value: String) 

     It sets values on the profile. Passing a property that was already set with values will cause the old values to be removed.  

     BlueConicClient.setProfileValue("hobby", "tennis");
    

    Parameter property The profile property to add the values for.

    Parameter values The profile values to store.

       

     setProfileValues(name: String, values: String[]) 

     It sets values on the profile. Passing a property that was already set with values will cause the old values to be removed.  

     BlueConicClient.setProfileValues("hobbies", ["tennis", "soccer"]);
    

    Parameter property  The profile property to add the values for.

    Parameter values The profile values to store.

       

     setLocale(locale: String)

     Setter for the locale to get the parameters for. By default, the default locale configured in BlueConic is used.

    Note: the only valid locales currently are 'en_US' and 'nl_NL'.  

     BlueConicClient.setLocale("en_US");
    

    Parameter locale  The locale, e.g.‘en_US’.

    createEvent(eventType: String, properties: Object)

     Registers an event of the specified type with the given properties. For a “PAGEVIEW" event a screen name can be passed, so interactions can be restricted on the where tab in BlueConic. For a “VIEW", “CLICK" or “CONVERSION" event an interactionId should be passed to register the event for.  

     BlueConicClient.createEvent("PAGEVIEW", {
     "screenName": "Main/HOMETAB"
     });
     BlueConicCLient.createEvent("VIEW", {
     "interactionId": this.interactionId
     }):
    

     Parameter eventType The event type. (e.g:"PAGEVIEW","VIEW",“CLICK",“CONVERSION")

       Parameter properties A map with properties for the event.

       

     Register Methods

     Methods to register events and page views  

     registerPageView(screenName: String)

     Registers a page event. For a “PAGEVIEW" event a screen name can be passed, so interactions can be restricted on the where tab in BlueConic.  

     BlueConicClient.registerPageView("Main/HOMETAB");
    

     Parameter screenName The screen name for this page view  

    registerDialogueEvent(eventType: String, interactionId: String)

    Registers a dialogue event of the specified type with the given properties. For a “VIEW", “CLICK" or “CONVERSION" event an interactionId should be passed to register the event for.

    BlueConicClient.registerDialogueEvent("VIEW", this.interactionId):
    

    Parameter eventType The event type. (e.g:“VIEW",“CLICK",“CONVERSION")

    Parameter properties A map with properties for the event.

     

    Register user event Methods

     Methods to register events and page views

     registerClickEvent(selector: String)

     Register a user click. For the event, a selector can be passed to trigger BlueConic Listeners, to execute their logic.  

     BlueConicClient.registerClickEvent("#homeButton");
    

     Parameter selector  The selector, which can be used in the listener rules, to listen on       

    registerClickEventWithContext(selector: String, values: String[])

    Register a user click. For the event, a selector can be passed to trigger BlueConic Listeners, to execute their logic.

    BlueConicClient.registerClickEventWithContext("#homeButton", ["contextA","contextB"]);
    

    Parameter selector The selector, which can be used in the listener rules, to listen on Parameter values context of the click event    

    registerUpdateValuesEvent(selector: String, values: String[])

      Register a user update values event. For the event, a selector can be passed to trigger BlueConic Listeners, to execute their logic.

      BlueConicClient.registerUpdateValuesEvent("#updateHobby", ["tennis","soccer"]);
    

      Parameter selector The selector, which can be used in the listener rules, to listen on    Parameter values context of the update values event      

    registerAdvancedEvent(name: String, values: String[])

        Register a user update values event. For the event, a selector can be passed to trigger BlueConic Listeners, to execute their logic.     

        BlueConicClient.registerAdvancedEvent("facebookLike", ["+1"]);
    

        Parameter name The name of the advanced even, which can be used in the listener rules, to listen on

    Parameter values context of the advanced event

    Tip: Click on a version number to view a previous version's package page

    Current Tags

    • Version
      Downloads (Last 7 Days)
      • Tag
    • 1.3.1
      53
      • alpha
    • 2.0.0
      40
      • latest

    Version History

    Install

    npm i @blueconic/blueconic-react-native

    DownloadsWeekly Downloads

    114

    Version

    2.0.0

    License

    SEE LICENSE IN LICENSE

    Unpacked Size

    204 kB

    Total Files

    27

    Last publish

    Collaborators

    • bc-aruna
    • bc-garet
    • bc-lukasz
    • bc-basant
    • bc-caleb
    • bc-andrei
    • bc-justin
    • jaspergeurts
    • bc-saravanaa
    • bc-shilpa
    • bc-mike
    • bc-abhishek
    • bc-landon
    • bc-omar
    • bc-richard
    • bc-arthur
    • bc-caprice
    • bc-olaf
    • bc-bamboo
    • bc-bartvb
    • bc-edgars
    • blueconic-adm
    • ate
    • ynooijen
    • markmachielsen
    • bc-paulrutter
    • bartleusink
    • erikvl
    • karelb
    • patrick_atoon
    • stephanh
    • bc-stef
    • bc-marten
    • bc-dennis
    • bc-mattia
    • bc-natnael
    • bc-vreuls
    • bc-nicky
    • bc-tara
    • bc-koenvz
    • bc-merlijn
    • bc-jasperj
    • bc-gulliver
    • bc-don
    • bc-atieh
    • bc-sandra
    • egilreath
    • bc-koenro
    • bc-cordny
    • bc-saranya
    • bc-kent