Installation

To install the Appgain ionic plugin in your app, run the following commands

npm i https://github.com/Appgain/IonicAppgainNGX.git --save
ionic cordova plugin add https://github.com/Appgain/Cordova-SDK.git

Usage

Initializing

To initialize appgain SDK, call the following method on app start

async () => {
    try {
        await AppgainSDK.initSDK(
            "projectId",
            "apiKey", 
            true
        );
    } catch (error) {
        console.log("Error: ", error);
    }
}

Deferred Deep Linking

After a new user has installed your app, our SDK will detect if the app was installed from a smart deep link or not, if it's then our SDK will automatically route their flow to marketing campaign desired location in the app (not just to the default home screen).

To achieve that, appgain.io SDK must be installed in the app, and the matching process must be initiated

async () => {
    try {
        let result = await AppgainSDK.matchLink();
        console.log("result:", result);
    } catch (error) {
        console.log("Error: ", error);
    }
}

This function returns an empty json object if matching fails, and the following data if the matching succeeded:

Returned Field Description
smart_link_url the URL of smart deep link used to open or install the App
smart_link_id the Id of smart deep link used to open or install the App
smart_link_name the Id of smart deep link used to open or install the App
match_type how the device identification is done , it could be basic(Digital fingerprinting) or advertising_id
extra_data array of more data
extra_data.userId user Id that was appended to smart link url on opening it phase
params array of all paramaters appended to smart link url , like SDL URL?utm_source=fb
smart_link_primary primary redirection action

Marketing Automation

Send Automated and Personalized Push notifications, SMS or Emails based on your user’s actions and behavior using Apggain’s Powerful Automator, Know More Now!

  1. Create an auto message in Appgain Dashboard .
  2. Fire the auto message by using this code.
  3. you must use the same trigger event that was entered in step 1, as the TriggerPoint in the following code.

with Personalization

async () => {
    try {
        let personalization = {};
        personalization[key] = value;
        await AppgainSDK.fireAutomator("triggerPoint", personalization);
    } catch (error) {
        console.log("Error: ", error);
    }
}

without Personalization

async () => {
    try {
        await AppgainSDK.fireAutomator("triggerPoint", {});
    } catch (error) {
        console.log("Error: ", error);
    }
}

Revenue Tracking

async () => {
    try {
        await this.sdk.addPurchase(productName, amount, currency);
    } catch (error) {
        console.log("err:", error);
    }
}

App Events Logging

whenever you want to log user event , add below code

async () => {
    var type = "type";
    var action = "action";
    var extras = {key: "value"};
    try {
        await AppgainSDK.logEvent(type, action, extras);
    } catch (error) {
        console.log("Error: ", error);
    }
}

Notification Channels

To add user SMS notification channel

   try {
        await this.sdk.addNotificationChannel("SMS", userPhone);
    } catch (error) {
        console.log("err:", error);
    }

To add user email notification channel

    try {
        await this.sdk.addNotificationChannel("email", userPhone);
    } catch (error) {
        console.log("err:", error);
    }

Getting Appgain user Id

   try {
      let result = await this.sdk.getUserId();
      console.log("userId: ", result);
    } catch (error) {
      console.log("err:", error);
    }

Setting Appgain user Id

   try {
        await this.sdk.setUserId(newUserId);
    } catch (error) {
        console.log("err:", error);
    }

Updating user profile data

    try {
        let userData = {
            // user data
        };
        await AppgainSDK.updateUserData(userData);
    } catch (error) {
        console.log("Error: ", error);
    }

Android Specific Instructions

  • Inside the app/build.gradle file, make sure that multiDex is enabled:
    android{
        multiDexEnabled = true
    }
  • and in the end of your file add the following line
   apply plugin: 'com.google.gms.google-services'
  • open your project/build.gradle file and add following line under dependencies
 dependencies {  
    classpath 'com.google.gms:google-services:4.2.0'  
 }

  • also make sure you have the google-services.json file located in your application's app folder

Push Notification setup

firbase project settings


  • Go to Cloud Messaging tab and copy SenderID and Legacy server key

cloud settings

  • Open appgain dashboard

  • Go to APP BACKEND > Settings

  • Navigate to Android push tab

  • enter your SenderID and Server key

Appgain Android Push settings


    <script>
        window.intercomSettings = {
          app_id: "t1dhxh7r"
        };
    </script>
    <script>
      // We pre-filled your app ID in the widget URL: 'https://widget.intercom.io/widget/t1dhxh7r'
      (function(){var w=window;var ic=w.Intercom;if(typeof ic==="function"){ic('reattach_activator');ic('update',w.intercomSettings);}else{var d=document;var i=function(){i.c(arguments);};i.q=[];i.c=function(args){i.q.push(args);};w.Intercom=i;var l=function(){var s=d.createElement('script');s.type='text/javascript';s.async=true;s.src='https://widget.intercom.io/widget/t1dhxh7r';var x=d.getElementsByTagName('script')[0];x.parentNode.insertBefore(s,x);};if(w.attachEvent){w.attachEvent('onload',l);}else{w.addEventListener('load',l,false);}}})();
    </script>