Plumb5 Analytics SDK for Android Devices

The document details steps required to integrate Plumb5 Analytics SDK into your application for Android devices. For any questions or queries please email us at support@plumb5.com

Obtain your App key

Register with www.plumb5.com to obtain your AAP Key

Download P5Plugin.aar

The plugin is available for download at www.plumb5.com/Plumb5AndroidSDK.zip

Integrate the SDK with the project

Android Studio:

  • Step 1 : Select File New New Module
  • Step 2 : Select " Import .JAR or .AAR Package under More Modules.
  • Step 3 : Select the P5Analytics.jar by clicking on the File chooser.
  • Step 4 : Select Finish.
  • Step 5 : Right click on app folder Open Module Settings.
  • Step 6 : Select Dependency at the top right corner.
  • Step 7 : Select '+' symbol and choose 'Module Dependency' and It will list down the existing jar files.
  • Step 8 : Select plugin-release.aar

Eclipse

  • Step 1 : Add plugin-release.aar to your project's libs folder.
  • Step 2 : Right-click the JAR file and select Build Path Add to Build Path.

Code Integration

Firebase Cloud Messaging (FCM)

Import P5Plugin

import com.plugin.plumb5.P5Engine;

AndroidManifest.xml

Give Access to Internet (The SDK will send the collected data to the Plumb5 Server)

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

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

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

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

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

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

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

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

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

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

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

 

 

Note:

Also you have to give runtime permission READ_PHONE_STATE and ACCESS_FINE_lOCATION and ACCESS_COARSE_LOCATION if you are using Android -Marshmallow And above.Without giving run time permission READ_PHONE_STATE you can’t track data from our SDK.

Change application name for Tracking

<application android:name = "com.plugin.plumb5.P5Monitor" />

Add service and receiver for push notification before end of Application(</application>).

 

<service android:name = "com.plugin.plumb5.P5FireBasePushNotificationService">

<intent-filter>

android:name = "com.google.firebase.MESSAGING_EVENT"/>

</intent-filter>

</service>

 

<service android:name = "com.plugin.plumb5.P5FireBaseManager">

<intent-filter>

<action android:name = "com.google.firebase.INSTANCE_ID_EVENT"/>

</intent-filter>

</service>

 

<receiver android:name = "com.plugin.plumb5.P5Receiver">

<intent-filter>

<action android:name = "android.intent.action.BOOT_COMPLETED"/>

</intent-filter>

</receiver>

Add Dependencies

compile"com.google.firebase:firebase-auth:9.2.1" />

compile"com.google.firebase:firebase-core:9.2.1" />

compile"com.google.firebase:firebase-messaging:9.2.1" />

compile"com.google.android.gms:play-services-places:9.2.1" />

compile"com.google.code.gson:gson:2.3" />

compile"com.google.android.gms:play-services-wearable:9.2.1" />

apply plugin:"com.google.gms.google-services" />

In(Project:ProjectName)

classpath 'com.google.gms:google-services:3.1.0'

Configuration APIs and Start Session

Pass the APP KEY to P5Engine.p5Init method to start tracking the user actions .
P5Engine.p5Init(this,"App-KEY",CommunicationMode.FCM);

The client can add also addition properties like Screen Name and UserInfo
P5Engine.p5SetUserInfo(this,"Name", "test@gmail.com", "9916193622",”Extra Parameter”);

Load in-App banner

ImageView bmp5Image=(ImageView) findViewById(R.id.p5banner);
ImageView bmp5CloseImage=(ImageView) findViewById(R.id.p5close);
P5Engine.p5LoadBanner(this, bmp5Image, bmp5CloseImage);

Need to modify your activity's layout with this below layout.

(Example /app/src/main/res/layout/activity_main.xml in the editor.)

<FrameLayout android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_centerHorizontal = "true"
android:layout_alignParentBottom =
"true" />

<ImageView android:id= "@+id/p5banner"
android:layout_width = "wrap_content"
android:layout_height =
"wrap_content"
android:scaleType =
"fitEnd"
android:layout_gravity =
"center|bottom" />

<ImageView android:id= "@+id/p5close"
android:layout_width = "wrap_content"
android:layout_height =
"wrap_content"
android:layout_gravity = "left|bottom" />

</FrameLayout>

Get Event

Use the P5Eventdata() api to to get user event.

P5Engine.P5Eventdata(this, "BUTTON_CLICK", "BTN-1", “10”);

Get Transaction

Use the P5Transdata() api to to get user event.

JSONArray jsonTransaction = new JSONArray();

try { for(int i=0;i < 5;i++)

final JSONObject jsonItem =new JSONObject();
jsonItem.put("ProductId", 1);
jsonItem.put("ProductName", "samsung");
jsonItem.put("Quantity", 5);
jsonItem.put("TotalAmount", 200);
jsonItem.put("ProductImage", "");
jsonItem.put("OrderId", "234");
jsonItem.put("TransStatus", 0);
jsonTransaction.put(jsonItem); }
}
catch (JSONException ignored) { }
P5Engine.P5Transdata(this,jsonTransaction);

Post static form data

JSONArray DataList =new JSONArray();
DataList.put("sunny");
DataList.put("sunny@gmail.com");
DataList.put("991619345");
DataList.put("Male");
DataList.put("Bangalore");
DataList.put("Ready to buy"); }
P5Engine.P5PostStaticFormData(this, FormId, DataList);

Create chat

Context context;
EditText mEdit;
private P5ChatArrayAdapter chatArrayAdapter;
private ListView listView;

Bind chat messages

listView = (ListView) findViewById(R.id.P5Chat_list);

chatArrayAdapter = new P5ChatArrayAdapter(getApplicationContext(), R.layout.chat_template);

listView.setAdapter(chatArrayAdapter);

listView setTranscriptMode(ListView.TRANSCRIPT_MODE_ALWAYS_SCROLL);

listView.setStackFromBottom(true);

 

String tempid = "chat_template";
String MainContainerId = "P5MessageMainContainer";

String ContainerId = "P5MessageContainer";
String chatText = "P5ChatMessage"

String chatDate = "P5chatDate"

String messagecolorleft = "#dee1d4";

String messagecolorright = "#ADFBA2";

P5Engine.P5ChatInit (this, chatArrayAdapter, tempid, MainContainerId, ContainerId, chatText, chatDate, messagecolorleft, messagecolorright);

Post chat message

mEdit =(EditText) findViewById(R.id.txtChat);
if (mEdit.length() > 0) {
P5Engine.P5PostChat(this, mEdit.getText().toString(), chatArrayAdapter);
mEdit.setText("");
}

Chat screen layout

<RelativeLayout xmlns:android = "http://schemas.android.com/apk/res/android"
android:orientation = "vertical"
android:background = "@android:color/white"
android:padding = "10dp"
android:layout_width = "match_parent"
android:layout_height = "match_parent">

<TextView
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:text = "Chat Room"
android:paddingBottom = "10dp"
android:id = "@+id/txtVisitHead" />

<ListView
android:id = "@+id/P5Chat_list"
android:paddingTop = "25dp"
android:transcriptMode = "alwaysScroll"
android:divider = "@null"
android:dividerHeight = "8sp"
android:layout_above = "@+id/llSend"
android:layout_width = "wrap_content"
android:layout_height = "match_parent"/>

<RelativeLayout
android:id = "@+id/llSend"
android:layout_alignParentBottom = "true"
android:layout_width = "match_parent"
android:paddingTop = "5dp"
android:paddingBottom = "10dp"
android:paddingLeft = "0dp"
android:paddingRight = "0dp"
android:layout_height = "wrap_content" >

<EditText
android:id = "@+id/txtChat"
android:layout_toLeftOf = "@+id/btSend"
android:layout_alignBottom = "@+id/btSend"
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:capitalize = "characters"
android:gravity = "top"
android:hint = "Write a message"
android:inputType = "textCapSentences"
android:imeOptions = "actionSend" />

<Button
android:id = "@+id/btSend"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:gravity = "center_vertical|right"
android:paddingRight = "10dp"
android:layout_alignParentRight = "true"
android:text = "Send"
android:onClick = "postChat"
android:textSize = "18sp" >
</Button>

</RelativeLayout>
</RelativeLayout>

Chat message template layout

<RelativeLayout xmlns:android = "http://schemas.android.com/apk/res/android"
android:id = "@+id/P5MessageMainContainer"
android:layout_width = "fill_parent"
android:layout_height = "wrap_content" >

<RelativeLayout
android:id = "@+id/P5MessageContainer"
android:layout_width = "wrap_content"
android:layout_height= "wrap_content"
android:padding = "6dip">

<TextView
android:id = "@+id/P5ChatMessage"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_gravity = "center"
android:textSize = "16sp"
android:textColor = "@android:color/primary_text_light" />

<TextView
android:id = "@+id/P5chatDate"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:textColor = "#969191"
android:textSize = "12sp" />

</RelativeLayout>

</RelativeLayout>

Beacon Push Campaign

Import .AAR (estimote-sdk.aar) file
https://github.com/Estimote/Android-SDK/tree/master/EstimoteSDK

Need permission

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { String[] permission = { "android.permission.ACCESS_FINE_LOCATION"};
ActivityCompat.requestPermissions(this, permission, 1); }

Geofence Push Campaign

Add this service line before end of application in AndroidManifest.xml for Geofence Push Notification
<service android:name = "com.plugin.plumb5.P5GeoMonitorService" />

Google Cloud Messaging (GCM)

Import P5Plugin

import com.plugin.plumb5.P5Engine;

AndroidManifest.xml

Give Access to Internet (The SDK will send the collected data to the Plumb5 Server)

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

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

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

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

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

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

<uses-permission android:name = "com.google.android.c2dm.permission.RECEIVE" />

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

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

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

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

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

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

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

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

 

<permission android:name="com.plumb5.p5demo(Use your package name).permission.C2D_MESSAGE" android:protectionLevel="signature" />

<uses-permission android:name = "com.plumb5.p5demo(Use your package name).permission.C2D_MESSAGE"/>

 

Note:

Also you have to give runtime permission READ_PHONE_STATE and ACCESS_FINE_lOCATION and ACCESS_COARSE_LOCATION if you are using Android -Marshmallow And above.Without giving run time permission READ_PHONE_STATE you can’t track data from our SDK.

Change application name for Tracking

<application

android:name = "com.plugin.plumb5.P5Monitor" />

Add service and receiver for push notification before end of Application(</application>).

 

<service android:name = "com.plugin.plumb5.P5GcmPushNotificationService"

android:exported="false">

<intent-filter>

<action android:name = "com.google.android.c2dm.intent.RECEIVE"/>

</intent-filter>

</service>

 

<receiver android:name="com.google.android.gms.gcm.GcmReceiver"

android:exported="true"

android:permission="com.google.android.c2dm.permission.SEND">

<intent-filter>

<action android:name="com.google.android.c2dm.intent.RECEIVE" />

<category android:name="com.plumb5.p5demo(Use your package name)" />  

</intent-filter>

</receiver>

 

<receiver android:name = "com.plugin.plumb5.P5Receiver">

<intent-filter>

<action android:name = "android.intent.action.BOOT_COMPLETED"/>

</intent-filter>

</receiver>

Add Dependencies

compile"com.google.android.gms:play-services-gcm:8.4.0" />

compile"com.google.android.gms:play-services-location:8.4.0" />

compile"com.google.android.gms:play-services-places:9.2.1" />

compile"com.google.android.gms:play-services-wearable:9.2.1" />

compile"com.google.code.gson:gson:2.3" />

Configuration APIs and Start Session

Pass the APP KEY to P5Engine.p5Init method to start tracking the user actions .
P5Engine.p5Init(this,"App-KEY",CommunicationMode.GCM);

The client can add also addition properties like Screen Name and UserInfo

P5Engine.p5SetUserInfo(this,"Name", "test@gmail.com", "9916193622",”Extra Parameter”);

Load in-App banner

ImageView bmp5Image=(ImageView) findViewById(R.id.p5banner);
ImageView bmp5CloseImage=(ImageView) findViewById(R.id.p5close);
P5Engine.p5LoadBanner(this, bmp5Image, bmp5CloseImage);

Need to modify your activity's layout with this below layout.

(Example /app/src/main/res/layout/activity_main.xml in the editor.)

<FrameLayout

android:layout_width = "wrap_content"

android:layout_height = "wrap_content"

android:layout_centerHorizontal = "true"

android:layout_alignParentBottom = "true" />

 

<ImageView

android:id= "@+id/p5banner"

android:layout_width = "wrap_content"

android:layout_height = "wrap_content"

android:scaleType = "fitEnd"

android:layout_gravity = "center|bottom" />

 

<ImageView

android:id= "@+id/p5close"

android:layout_width = "wrap_content"

android:layout_height = "wrap_content"

android:layout_gravity = "left|bottom" />

</FrameLayout>

Get Event

Use the P5Eventdata() api to to get user event.

P5Engine.P5Eventdata(this, "BUTTON_CLICK", "BTN-1", “10”);

Get Transaction

Use the P5Transdata() api to to get user event.

JSONArray jsonTransaction = new JSONArray();

try { for(int i=0;i < 5;i++)

{ final JSONObject jsonItem = new JSONObject();
jsonItem.put("ProductId", 1);
jsonItem.put("ProductName", "samsung");
jsonItem.put("Quantity", 5);
jsonItem.put("TotalAmount", 200);
jsonItem.put("ProductImage", "");
jsonItem.put("OrderId", "234");
jsonItem.put("TransStatus", 0);
jsonTransaction.put(jsonItem); }
}
catch (JSONException ignored) { }
P5Engine.P5Transdata(this,jsonTransaction);

Post static form data

JSONArray DataList =new JSONArray();
DataList.put("sunny");
DataList.put("sunny@gmail.com");
DataList.put("991619345");
DataList.put("Male");
DataList.put("Bangalore");
DataList.put("Ready to buy"); }
P5Engine.P5PostStaticFormData(this, FormId, DataList);

Create chat

Context context;
EditText mEdit;
private P5ChatArrayAdapter chatArrayAdapter;
private ListView listView;

Bind chat messages

listView = (ListView) findViewById(R.id.P5Chat_list);

chatArrayAdapter = new P5ChatArrayAdapter(getApplicationContext(), R.layout.chat_template);

listView.setAdapter(chatArrayAdapter);

listView setTranscriptMode(ListView.TRANSCRIPT_MODE_ALWAYS_SCROLL);

listView.setStackFromBottom(true);

 

String tempid = "chat_template";
String MainContainerId = "P5MessageMainContainer";

String ContainerId = "P5MessageContainer";
String chatText = "P5ChatMessage"

String chatDate = "P5chatDate"

String messagecolorleft = "#dee1d4";

String messagecolorright = "#ADFBA2";

P5Engine.P5ChatInit (this, chatArrayAdapter, tempid, MainContainerId, ContainerId, chatText, chatDate, messagecolorleft, messagecolorright);

Post chat message

mEdit =(EditText) findViewById(R.id.txtChat);
if (mEdit.length() > 0) {
P5Engine.P5PostChat(this, mEdit.getText().toString(), chatArrayAdapter);
mEdit.setText("");
}

Chat screen layout

<RelativeLayout xmlns:android = "http://schemas.android.com/apk/res/android"
android:orientation = "vertical"
android:background = "@android:color/white"
android:padding = "10dp"
android:layout_width = "match_parent"
android:layout_height = "match_parent">

<TextView
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:text = "Chat Room"
android:paddingBottom = "10dp"
android:id = "@+id/txtVisitHead" />

<ListView
android:id = "@+id/P5Chat_list"
android:paddingTop = "25dp"
android:transcriptMode = "alwaysScroll"
android:divider = "@null"
android:dividerHeight = "8sp"
android:layout_above = "@+id/llSend"
android:layout_width = "wrap_content"
android:layout_height = "match_parent"/>

<RelativeLayout
android:id = "@+id/llSend"
android:layout_alignParentBottom = "true"
android:layout_width = "match_parent"
android:paddingTop = "5dp"
android:paddingBottom = "10dp"
android:paddingLeft = "0dp"
android:paddingRight = "0dp"
android:layout_height = "wrap_content" >

<EditText
android:id = "@+id/txtChat"
android:layout_toLeftOf = "@+id/btSend"
android:layout_alignBottom = "@+id/btSend"
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:capitalize = "characters"
android:gravity = "top"
android:hint = "Write a message"
android:inputType = "textCapSentences"
android:imeOptions = "actionSend" />

<Button
android:id = "@+id/btSend"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:gravity = "center_vertical|right"
android:paddingRight = "10dp"
android:layout_alignParentRight = "true"
android:text = "Send"
android:onClick = "postChat"
android:textSize = "18sp" >
</Button>

</RelativeLayout>
</RelativeLayout>

Chat message template layout

<RelativeLayout xmlns:android = "http://schemas.android.com/apk/res/android"
android:id = "@+id/P5MessageMainContainer"
android:layout_width = "fill_parent"
android:layout_height = "wrap_content" >

<RelativeLayout
android:id = "@+id/P5MessageContainer"
android:layout_width = "wrap_content"
android:layout_height= "wrap_content"
android:padding = "6dip">

<TextView
android:id = "@+id/P5ChatMessage"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_gravity = "center"
android:textSize = "16sp"
android:textColor = "@android:color/primary_text_light" />

<TextView
android:id = "@+id/P5chatDate"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:textColor = "#969191"
android:textSize = "12sp" />

</RelativeLayout>

</RelativeLayout>

Beacon Push Campaign

Import .AAR (estimote-sdk.aar) file
https://github.com/Estimote/Android-SDK/tree/master/EstimoteSDK

Need permission

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { String[] permission = { "android.permission.ACCESS_FINE_LOCATION"};
ActivityCompat.requestPermissions(this, permission, 1); }

Geofence Push Campaign

Add this service line before end of application in AndroidManifest.xml for Geofence Push Notification
<service android:name = "com.plugin.plumb5.P5GeoMonitorService" />

Top