Localytics Integration

Localytics

Localytics is a closed-loop app analytics and marketing platform that helps brands acquire, engage, and retain users.

Titanium Integration

You can find the titanium modules for localytics here:

Github Module

Let's start by adding the localytics key on tiapp.xml:

For iOS add it on <dict>:

               <key>LocalyticsAppKey</key> <string>00-00-00</string> 
              

For android add it on <application>:

               <uses-permission android:name="android.permission.WAKE_LOCK"/> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/> <uses-permission android:name="com.mulletstar.getsubscribers.permission.C2D_MESSAGE"/> <permission android:name="com.mulletstar.getsubscribers.permission.C2D_MESSAGE" android:protectionLevel="signature"/> 
              

Also add the following permissions for android:

                 <service android:name="com.localytics.gcm.GCMIntentService"/> <receiver android:name="com.localytics.gcm.GCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED"/> <category android:name="android.intent.category.HOME"/> </intent-filter> <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE"/> <category android:name="com.mulletstar.getsubscribers"/> </intent-filter> <intent-filter> <action android:name="com.google.android.c2dm.intent.REGISTRATION"/> <category android:name="com.mulletstar.getsubscribers"/> </intent-filter> </receiver> <receiver android:name="com.localytics.android.ReferralReceiver" android:exported="true"> <intent-filter> <action android:name="com.android.vending.INSTALL_REFERRER"/> </intent-filter> </receiver> 
              

Also don't forget to add the following on the <modules> part:

                 <module platform="android" version="3.0.1">com.localytics</module> <module platform="iphone" version="3.0.0">com.localytics</module> 
              

Now let's start intializing localytics in the app:

                 var localyticsModule = require('com.localytics'); localyticsModule.autoIntegrate(); localyticsModule.registerPush(); 
              

This will automatically save the users device id unto their database which we can use when we want to send push notifications on localytics dashboard.

Now let's track the users details(we can do this every after login):

               localyticsModule.setCustomerEmail("testing@localytics.com"); localyticsModule.setCustomerName("John Doe"); localyticsModule.setCustomerId("124525"); localyticsModule.setCustomerData("super special id", "1242444"); 
            

You can also create your own custom data as seen above.

You can also track screens:

               localyticsModule.tagScreen("Screen 2"); 
            

And also track events:

               localyticsModule.tagEvent("Test Event", {"animal":"cat", "name": "test", "action": "clicked"}, 50); 
            
  • The first parameter is the event name
  • The second parameter is a dictionary which is a list of events you want to include on that event, this is where you add additional info of that event
  • The third parameter is for the lifeTimeValue that you want to include, this is commonly used on iap purchases

How to send push notifications using Localytics API

This will require you the localytics_key, localytics_api_key and localytics_api_secret, you can get this on the localytics dashboard.

Here's our server implementation for sending the push:

               extra = extra or {} extra = { 'type': pushtype, 'data': extra } params = { # duplicate request ID's will be accepted (202) but will not be sent to any devices 'request_id': generate_unique_string(target_id, 'getsubsv3', time.time()), 'campaign_key': None, 'target_type': 'customer_id', 'messages': [ { 'target': str(target_id), 'alert': message, 'ios': { 'sound': 'default.wav', 'badge': 1, 'category': 'default', 'extra': extra, }, 'android': { 'category': 'default', 'extra': extra, }, }, ] } url = 'https://messaging.localytics.com/v2/push/{}'.format(app_id) response = requests.post(url, **{ 'auth': HTTPBasicAuth(LOCALYTICS_API_KEY, LOCALYTICS_API_SECRET), 'data': json.dumps(params), 'headers': { 'Content-Type':'application/json' } }) 
            
  • request_id must be a unique id on your app key that you need to send
  • target is the users customerId that you set on the app(which for us is the users pk)
  • alert is the message that you want to send
  • and the rest are extra details that you want to add

Blog Posts by Noel Flores

Mobile Development

Localytics Integration

Localytics Localytics is a closed-loop app analytics and marketing platform that helps brands acquire, engage, and retain users.

Read More