O slideshow foi denunciado.
Utilizamos seu perfil e dados de atividades no LinkedIn para personalizar e exibir anúncios mais relevantes. Altere suas preferências de anúncios quando desejar.
 
 
 
 
 
 
 
 
Mixpanel Integration with Android
BrainBox Network. Copyright@2015. All rights reserved
 
 
The document provides steps to integrate Android with Mixpanel integration.
The integration process requires following s...
 
INSTRUCTIONS 
 
 
 
➔ Please Follow these instructions:
➔ Create Google Account
➔ Open below given Url:
https://console....
 
CREATE NEW PROJECT 
 
 
 
 
➔ Give name of new project in the “Project” field.
➔ Click on “Enable and Manage API” button...
 
 
 
 
➔ Again Click on “Create Credentials”
➔ Select “API key”
➔ Then select Server key
➔ Then click Create Button
 
 
 ...
 
➔ Open below link on browser
https://developers.google.com/mobile/add
➔ Pick a platform (Android / IOS)
➔ Select your Ap...
 
 
 
 
 
 
 
 
 
 
 
 
➔ Click on “Download google‐services.json”
➔ After downloading, copy the google‐services.json to t...
 
DASHBOARD SETUP 
 
➔ Open Mixpanel website and Create new account or Login 
➔ Click on “Create Project”
➔ Write your “Pr...
 
CONFIGURATION OF PROJECT 
 
➔ Click on Settings Icon, showing in the left bottom corner.
 
 
 
 
➔ Save Project Token, f...
 
 
➔ Click on Notifications Icon
➔ Paste your Android GCM Service key
➔ Click on “Save Changes”
➔ Now click on “Close”
 
...
 
ANDROID CODE SETUP 
 
➔ Add dependencies to App/build.gradle:
Compile 'com.google.android.gms:play‐services:8.4.0'
Compi...
 
➔ Add permissions to app/src/main/AndroidManifest.xml
<uses‐permission android:name="android.permission.INTERNET" />
<us...
 
➔ Paste below code in “Application” tag in manifest
<receiver android:name="com.mixpanel.android.mpmetrics.GCMReceiver"
...
 
 
➔ Setup Java Code in App
MixpanelAPI mixpanel = MixpanelAPI.getInstance(this,<MIXPANEL TOKEN>");
mixpanel.identify(GEN...
 
➔ Setup User Profile in Mixpanel
JSONObject messageProps = new JSONObject();
try {
messageProps.put("User Age","25");
} ...
 
➔ Set Super Properties
try {
final JSONObject userProfile = new JSONObject();
userProfile.put("$name" ,"TEST");
userProf...
 
➔ Tracking User Action
mixpanel.track(“EVENT_NAME");
WRITE BELOW CODE IN ACTIVITY
@Override
protected void onDestroy() {...
 
CUSTOM NOTIFICATION 
 
➔ CREATE OWN RECEIVER (For Ex. My Receiver) :
➔ Insert Below code in app/src/main/AndroidManifest...
 
 
➔ MYRECEIVER.JAVA class CODE
public class MyReceiver extends BroadcastReceiver {
Context context;
@Override
public voi...
 
Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent1 =
PendingIntent.getActivity(context, 0, notificationIntent, 0);
...
 
}
SEND IMAGE WITH PUSH NOTIFICATION FROM MIXPANEL 
DASHBOARD 
 
➔ Create Push Notification in Mixpanel
➔ Set Audience
➔ ...
 
FOR FURTHER INFORMATION 
 
➔ https://mixpanel.com/help/reference/android
➔ https://github.com/mixpanel/mixpanel‐android
...
 
Thank You So Very Much
For queries please write on ​ashish@mobifly.in
Developed By
Mohit Saini
Android Developer ‐ Mobif...
Próximos SlideShares
Carregando em…5
×

Mixpanel Integration in Android

322 visualizações

Publicada em

The document provides steps to integrate Mixpanel in your android application. Mixpanel provides efficient dashboard for mobile analytics and to send push notification and in app messages

Publicada em: Tecnologia
  • Seja o primeiro a comentar

  • Seja a primeira pessoa a gostar disto

Mixpanel Integration in Android

  1. 1.                 Mixpanel Integration with Android BrainBox Network. Copyright@2015. All rights reserved  
  2. 2.   The document provides steps to integrate Android with Mixpanel integration. The integration process requires following steps ‐ 1. Instructions 2. Create New Project 3. Dashboard Setup 4. Configuration of Project 5. Android Code Setup 6. Custom Notification 7. Send Image with Push Notification 8. Further Information BrainBox Network. Copyright@2015. All rights reserved  
  3. 3.   INSTRUCTIONS        ➔ Please Follow these instructions: ➔ Create Google Account ➔ Open below given Url: https://console.developers.google.com ➔ Click on “Select Project” dropdown. BrainBox Network. Copyright@2015. All rights reserved  
  4. 4.   CREATE NEW PROJECT          ➔ Give name of new project in the “Project” field. ➔ Click on “Enable and Manage API” button. ➔ Enable these services by “Google Cloud Messaging” ➔ Click on “Credentials tag” (In the left side or below of overview) ➔ Click on “Create Credentials” ➔ Select “API key” ➔ Then select android key ➔ Select “+Add Package name and fingerprint” ➔ Enter your “Package name” ➔ Enter your “SHA‐1 Key” 1. Open CMD from your system Java bin directory For Ex:​“C:Program Files (x86)Javajdk1.6.0bin” 2. Run following command in CMD 3. Keytool ‐list ‐v ‐keystore "C:UsersAdmin.androiddebug.keystore"​(Mention your system path till “debug.keystore” file) 4. ‐alias androiddebugkey ‐storepass android ‐keypass android 5. Hence SHA‐1 KEY will shown in output 6. After fill all information Select Create & Save android key in somewhere. BrainBox Network. Copyright@2015. All rights reserved  
  5. 5.         ➔ Again Click on “Create Credentials” ➔ Select “API key” ➔ Then select Server key ➔ Then click Create Button           BrainBox Network. Copyright@2015. All rights reserved  
  6. 6.   ➔ Open below link on browser https://developers.google.com/mobile/add ➔ Pick a platform (Android / IOS) ➔ Select your App name ➔ Write your “Package name” in android package name box ➔ Select “CONTINUE TO Choose and configure service” ➔ Adding services which you wants ➔ For push notification enable cloud messaging ➔ Select continue to generate configuration files               BrainBox Network. Copyright@2015. All rights reserved  
  7. 7.                         ➔ Click on “Download google‐services.json” ➔ After downloading, copy the google‐services.json to the app/ or mobile/module directory in your Android project                 BrainBox Network. Copyright@2015. All rights reserved  
  8. 8.   DASHBOARD SETUP    ➔ Open Mixpanel website and Create new account or Login  ➔ Click on “Create Project” ➔ Write your “Project name” then on “Create Project” button ➔ Click on “Create Project​”                  BrainBox Network. Copyright@2015. All rights reserved  
  9. 9.   CONFIGURATION OF PROJECT    ➔ Click on Settings Icon, showing in the left bottom corner.         ➔ Save Project Token, for use it further       BrainBox Network. Copyright@2015. All rights reserved  
  10. 10.     ➔ Click on Notifications Icon ➔ Paste your Android GCM Service key ➔ Click on “Save Changes” ➔ Now click on “Close”                 BrainBox Network. Copyright@2015. All rights reserved  
  11. 11.   ANDROID CODE SETUP    ➔ Add dependencies to App/build.gradle: Compile 'com.google.android.gms:play‐services:8.4.0' Compile 'com.mixpanel.android:mixpanel‐android:4.8.0'                                         BrainBox Network. Copyright@2015. All rights reserved  
  12. 12.   ➔ Add permissions to app/src/main/AndroidManifest.xml <uses‐permission android:name="android.permission.INTERNET" /> <uses‐permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <uses‐permission android:name="android.permission.GET_ACCOUNTS" /> <uses‐permission android:name="android.permission.WAKE_LOCK" /> <permission android:name=“<YOUR_APPLICATION_PACKAGE>.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <uses‐permission android:name="<YOUR_APPLICATION_PACKAGE>.permission.C2D_MESSAGE" />             BrainBox Network. Copyright@2015. All rights reserved  
  13. 13.   ➔ Paste below code in “Application” tag in manifest <receiver android:name="com.mixpanel.android.mpmetrics.GCMReceiver" android:permission="com.google.android.c2dm.permission.SEND" > <intent‐filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> <category android:name="YOUR_PACKAGE_NAME" /> </intent‐filter> </receiver>                                     BrainBox Network. Copyright@2015. All rights reserved  
  14. 14.     ➔ Setup Java Code in App MixpanelAPI mixpanel = MixpanelAPI.getInstance(this,<MIXPANEL TOKEN>"); mixpanel.identify(GENERATE DISTINCT ID); MixpanelAPI.People people = mixpanel.getPeople(); people.identify(SET_USER_ID); people.initPushHandling(GOOGLE_PROJECT_NUMBER); people.showNotificationIfAvailable(this);             BrainBox Network. Copyright@2015. All rights reserved  
  15. 15.   ➔ Setup User Profile in Mixpanel JSONObject messageProps = new JSONObject(); try { messageProps.put("User Age","25"); } catch (JSONException e) { e.printStackTrace(); } mixpanel.registerSuperPropertiesOnce(messageProps); OR mixpanel.registerSuperProperties(messageProps);                       BrainBox Network. Copyright@2015. All rights reserved  
  16. 16.   ➔ Set Super Properties try { final JSONObject userProfile = new JSONObject(); userProfile.put("$name" ,"TEST"); userProfile.put("$email" , "ABC@GMAIL.COM"); String timeStamp = new SimpleDateFormat("yyyy‐MM‐dd HH:mm:ss").format(new Date()); userProfile.put("$created", timeStamp); mixpanel.getPeople().set(userProfile); } catch (JSONException e) { e.printStackTrace(); }                 BrainBox Network. Copyright@2015. All rights reserved  
  17. 17.   ➔ Tracking User Action mixpanel.track(“EVENT_NAME"); WRITE BELOW CODE IN ACTIVITY @Override protected void onDestroy() { super.onDestroy(); mixpanel.flush(); }                   BrainBox Network. Copyright@2015. All rights reserved  
  18. 18.   CUSTOM NOTIFICATION    ➔ CREATE OWN RECEIVER (For Ex. My Receiver) : ➔ Insert Below code in app/src/main/AndroidManifest.xml <receiver android:name=“.My Receiver" android:permission="com.google.android.c2dm.permission.SEND"> <intent‐filter> <action android:name="com.google.android.c2dm.intent.RECEIVE"/> <category android:name="com.google.android.gcm.demo.app"/> </intent‐filter> <intent‐filter> <action android:name=“<GIVEN NAME (MYBROADCAST)>"> </action> </intent‐filter> </receiver>                           BrainBox Network. Copyright@2015. All rights reserved  
  19. 19.     ➔ MYRECEIVER.JAVA class CODE public class MyReceiver extends BroadcastReceiver { Context context; @Override public void onReceive(Context context, Intent intent) { Bundle data = intent.getExtras(); String notificationMessage = data.getString("mp_message"); this.context=context; if(data.containsKey("IMAGE_KEY")) { //NOTIFICATION WITH IMAGE String image_url = data.getString("IMAGE_URL"); new DownloadImage().execute(image_url,notificationMessage); } else { //NOTIFICATION WITHOUT IMAGE simpleNotification(notificationMessage); } } public class DownloadImage extends AsyncTask<String,Void,Bitmap> { Bitmap message_bitmap = null; @Override protected Bitmap doInBackground(String... parms) { try { URL url = new URL(parms[0]); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoInput(true); connection.connect(); InputStream input = connection.getInputStream(); message_bitmap = BitmapFactory.decodeStream(input); int icon = R.mipmap.ic_launcher; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); String title = "<APP_TITLE>"; Intent notificationIntent = null; notificationIntent = new Intent(Intent.ACTION_VIEW); notificationIntent.addCategory(Intent.CATEGORY_BROWSABLE); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | BrainBox Network. Copyright@2015. All rights reserved  
  20. 20.   Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent1 = PendingIntent.getActivity(context, 0, notificationIntent, 0); Notification notification = new NotificationCompat.Builder(context) .setContentTitle(title) .setContentText(parms[1]) .setContentIntent(intent1) .setSmallIcon(icon) .setWhen(when) .setStyle(new NotificationCompat.BigPictureStyle().bigPicture(message_bitmap)) .build(); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, notification); } catch (Exception e) { e.printStackTrace(); } return message_bitmap; } @Override protected void onPostExecute(Bitmap aVoid) { super.onPostExecute(aVoid); } } public void simpleNotification(String message) { int icon = R.mipmap.ic_launcher; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); String title = "<APP_TITLE>"; Intent notificationIntent = null; notificationIntent = new Intent(Intent.ACTION_VIEW); notificationIntent.addCategory(Intent.CATEGORY_BROWSABLE); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent1 =PendingIntent.getActivity(context, 0, notificationIntent, 0); Notification notification = new NotificationCompat.Builder(context) .setContentTitle(title) .setContentText(message) .setContentIntent(intent1) .setSmallIcon(icon) .setWhen(when) .build(); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, notification); } BrainBox Network. Copyright@2015. All rights reserved  
  21. 21.   } SEND IMAGE WITH PUSH NOTIFICATION FROM MIXPANEL  DASHBOARD    ➔ Create Push Notification in Mixpanel ➔ Set Audience ➔ Set your Push Notification ➔ Set Custom data (Extra data) ➔ For Image send Image_key For Eg: Image_key ‐> “12345”) and Image_url ‐> “​http://tineye.com/images/widgets/mona.jpg​” ➔ In Custom data ‐> In Json form‐>Send                     BrainBox Network. Copyright@2015. All rights reserved  
  22. 22.   FOR FURTHER INFORMATION    ➔ https://mixpanel.com/help/reference/android ➔ https://github.com/mixpanel/mixpanel‐android                                 BrainBox Network. Copyright@2015. All rights reserved  
  23. 23.   Thank You So Very Much For queries please write on ​ashish@mobifly.in Developed By Mohit Saini Android Developer ‐ Mobifly mobifly.in     BrainBox Network. Copyright@2015. All rights reserved  

×