Search results for "{{ search.query }}"

No results found for "{{search.query}}". 
View All Results

Integration(Old)

Generating GCM Push Notification Key

  1. Create a new project at https://console.developers.google.com/project for your app

  2. Go to this newly created project in projects page

  3. Expand top-left project section and notedown your project number. Keep this handy:

  1. Choose API's from APIs and auth menu item from left section and click Cloud Messaging for Android under Mobile API's section from the right section

  2. Click on Enable API

  3. Now click Credentials from APIs and auth menu item from left section and then click Add credentials from popup menu in the center of the page and choose API Key and then Server Key. See screenshot:

  1. Give it any name and leave the Accept requests from these server IP addresses section as is and click Create.

  2. Note down this Server Key and keep it handy. We'll be needing these for push notifications. See screenshot:

Android Studio SDK Setup

WebEngage Android SDK is hosted on jcenter maven repository.
Update your project's build.gradle script to include jcenter.

repositories {
 	...
    
  jcenter()
  
  ...
}

Include WebEngage dependencies in your app/build.gradle

//WebEngage SDK
compile 'com.webengage:android-sdk:2.+'

//Required for push notification
compile 'com.android.support:support-v4:24.2.1' //version 24.+ is required for carousel push notifications
compile 'com.google.android.gms:play-services-gcm:10.0.1'

//Required for location tracking
compile 'com.google.android.gms:play-services-location:10.0.1'

Note: Make sure to go through migration guide every time after updating to latest version.

Manifest Changes

1. Enabling/disabling Debug Mode:

<meta-data
  android:name="com.webengage.sdk.android.debug"
  android:value="true" />
  • Can be true or false.
  • When debug mode is true debug logs from the SDK are printed onto console.
  • These logs shows various activities happening inside the SDK which are useful for the app developer, such as presence of compulsory permissions, meta tags, services, receivers, etc. required by the SDK, events being tracked, logged-in user identifier, etc.
  • Log-level can be set using WebEngage's logging API. Refer: API Section for more details

Remove this flag or set it to false before making release build of your application.

2. Add following meta-data under application tag of your AndroidManifest.xml:

<meta-data
  android:name="com.webengage.sdk.android.key"
  android:value="YOUR_WEBENGAGE_LICENSE_CODE" />

3. Add following services under application tag of your AndroidManifest.xml:

// required for event processing
<service android:name="com.webengage.sdk.android.ExecutorService" />

// required for event logging
<service android:name="com.webengage.sdk.android.EventLogService" />

4. Add following Activity under application tag of your AndroidManifest.xml:

<activity android:name="com.webengage.sdk.android.actions.render.WebEngageActivity"
            android:theme="@android:style/Theme.Translucent"
            android:configChanges="orientation|screenSize"
            />

5. Add following permissions under manifest tag:

// required by WebEngage
<uses-permission android:name="android.permission.INTERNET"/>

// optional,but highly recommended
<uses-permission android:name="android.permission.WAKE_LOCK" />  

6. GCM/FCM SETUP:

6.1. If GCM/FCM Registration and message handling for push messaging should be handled by WebEngage SDK, add following to your manifest:

1 meta-data

  <meta-data
    android:name="com.webengage.sdk.android.auto_gcm_registration"
    android:value="true" />

  <meta-data
    android:name="com.webengage.sdk.android.project_number"
    android:value="$YOUR_GCM/FCM_PROJECT_NUMBER" />
  • Make sure to prefix “YOUR_GCM/FCM_PROJECT_NUMBER” with a ‘$’ sign.

2 permissions

  <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
  <permission
    android:name="YOUR.PACKAGE.NAME.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />
  <uses-permission android:name="YOUR.PACKAGE.NAME.permission.C2D_MESSAGE" />

3 receiver

<receiver android:name="com.webengage.sdk.android.WebEngageReceiver"
    android:permission="com.google.android.c2dm.permission.SEND">
    <intent-filter>
      <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        <action android:name="com.webengage.sdk.android.intent.ACTION" />
        <category android:name="YOUR.PACKAGE.NAME" />
      </intent-filter>
  </receiver>
  • Replace YOUR.PACKAGE.NAME with your package name

6.2. Else, if GCM/FCM Registration and messaging is already being handled by your app, or you plan to handle it yourself, add following to your manifest:

1 meta-data

<meta-data
    android:name="com.webengage.sdk.android.auto_gcm_registration"
    android:value="false" />

2 receiver

<receiver
    android:name="com.webengage.sdk.android.WebEngageReceiver">
    <intent-filter>
        <action android:name="com.webengage.sdk.android.intent.ACTION" />
        <category android:name="YOUR.PACKAGE.NAME" />
    </intent-filter>
</receiver>

7. LOCATION TRACKING SET-UP:

Add following meta-data under application tag of your AndroidManifest.xml:

  // If WebEngage should enable location tracking, set it to true, otherwise set it to false. Default: TRUE
  <meta-data
    android:name="com.webengage.sdk.android.location_tracking"
    android:value="true" />

If above meta-data is set to true then add following permission under manifest tag of your
AndroidManifest.xml:

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

Apps targeting Android Marshmallow(API 23) and later will prompt user to grant permission at runtime , instead of install time . if permission is granted then call setLocationTracking api with true argument.

8. For WebEngage Attribution tracking, set-up an INSTALL-REFERRER:

Add following receiver under the application tag of your AndroidManifest.xml

Already have an install tracker

<receiver
  android:name="com.webengage.sdk.android.InstallTracker"
  android:exported="true">
  <intent-filter>
    <action android:name="com.android.vending.INSTALL_REFERRER" />
  </intent-filter>
</receiver>

Basic SDK Integration

1. Automatic

This approach is only supported in Android 4.0(API level 14, >99% coverage as of February 2017) and later. So, if you are developing your app to support minimal 14 API level, we recommend to use this approach as it is easy to integrate and requires less boilerplate.

1.1 If you don't have a custom Application class, create one and specify the name in your AndroidManifest.xml
  <application
    android:name=".MyApplication"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name">
1.2. Now, In your Application's onCreate() method, register WebEngageActivityLifeCycleCallbacks.
  public class MyApplication extends Application {
   @Override
   public void onCreate() {
    super.onCreate();
    // Register WebEngageActivityLifeCycleCallabcks
    registerActivityLifecycleCallbacks(new WebEngageActivityLifeCycleCallbacks(this));
   }
  }

registerActivityLifecycleCallbacks should be called before calling any method on WebEngage Object. You might need to take special care of the case where you are calling registerActivityLifecycleCallbacks in a thread, other than the main UI thread.

2. Manual

Use this approach if you plan to target devices below Android API level 14 also

2.1 If you don't have a custom Application class, create one, and specify the name in your AndroidManifest.xml
<application
	android:name=".MyApplication"
	android:icon="@drawable/ic_launcher"
	android:label="@string/app_name">
2.2 Now, In your application's onCreate() method, initialize WebEngage:
public class MyApplication extends Application {
  @Override
  public void onCreate() {
    super.onCreate();
    // Integrate WebEngage
    WebEngage.engage(this);
  }}

WebEngage.engage(this) should be called before calling any method on WebEngage Object. You might need to take special care of the case where you are calling WebEngage.engage(this) in a thread, other than the main UI thread.

2.3 Now, to enable users' session tracking, do the following for each Activity:

From onStart() of Activity call start(ACTIVITY_CONTEXT) on WebEngage:

@Override
public void onStart(){
  super.onStart();
  WebEngage.get().analytics().start(this);
}

From onStop() of Activity call stop(ACTIVITY_CONTEXT) of WebEngage:

public void onStop(){
  super.onStop();
  WebEngage.get().analytics().stop(this);
}

Make sure to repeat above 2 steps(the start() and stop()) for every other Activity in your application. This enables user session tracking and funnel generation for your app visitors.

Session tracking also logs the current activity the user is in. This can be used for example in games to track what all stages a user has went through. This is immensely helpful in funnel generation too where you can easily see where most of your users spend their times, and where they drop.

Disabling Session Tracking

If for some reason you would like to disabled session tracking for some activities (screens), you can do that by simply not calling WebEngage.get().analytics().start(this); and WebEngage.get().analytics().stop(this); in corresponding activities.
But, do make sure to keep them in sync. For every WebEngage's start() call, there should be a corresponding stop() call.

This is not a recommended practise though as it breaks the user funnel.


Screen

Screen is a placeholder for the events. Every event occurs in the context of a screen(or no screen) and there can be In-App Message targeting based on the screen rules. Also, every screen can be associated with some contextual data, which again can be part of the targeting rule for In-App messages. Your app can navigate between the screens or update the data associated with a screen using the screen APIs mentioned below.In case of android, single activity can have multiple screen (in case of single page application) and vice versa is also possible.

Screen APIs

Set Screen Name

@Overide
protected void onStart() {
   super.onStart();
   Analytics analytics = WebEngage.get().analytics();
   analytics.screenNavigated("PurchaseScreen");
}

Above api informs SDK that user has navigated to a new screen.Any previously set screen data is lost.The screen name passed can be used in targeting.

Set Screen Data

Analytics analytics = WebEngage.get().analytics();

Map<String,Object> screenData = new HashMap<String, Object>();
screenData.put("productId","~hs7674");
screenData.put("price",1200);

analytics.setScreenData(screenData);

Screen Name and Screen Data are the contextual information of current screen.This information is used in

  • custom rule based targetting
  • custom data tracking
  • token replacement in our engagement products

The above can be called any number of times after calling screenNavigated api.

Set screen name and data in one call

WebEngage.get().analytics().screenNavigated(String screenName,Map<String,Object> screenData)

Set every activity is a screen

WebEngage.get().setEveryActivityIsScreen(true);

This is a configuration API. Once this is set to true, analytics.screenNavigated(String screenName) is called automatically on start of every activity. The value of screenName parameter is fully qualified activity path of that activity.

All screen related API's can still be used after this has been used once to override the default effect of this configuration API.

Proguard Rules

1. Add following lines to your apps' proguard-rules.pro file

if WebEngage SDK version is below 1.8

-keep class com.webengage.sdk.android.**{*;}

-keep class * implements com.webengage.sdk.android.callbacks.PushNotificationCallbacks{*;}

-keep class * implements com.webengage.sdk.android.callbacks.LifeCycleCallbacks{*;}

-dontwarn com.webengage.sdk.android.**

else

-keep class com.webengage.sdk.android.**{*;}

-dontwarn com.webengage.sdk.android.**

NOTE: This is compulsory to do, as code obfuscation prevents SDK to discover required classes

Integration(Old)