UPDATED VERSION: Titanium Alloy iOS Android Modules: Count.ly Analytics, Push Notifications – Events, User Profiles, Messaging – Google Analytics Alternative
I have recently had to move away from Google Analytics for our Titanium Alloy Mobile apps for different reasons – I finally settled on Count.ly
Moving away from Google Analytics was a huge issue and I tried out many different mobile analytics providers with Titanium Alloy Modules including Yahoo`s Flurry Mobile analytics (could not get it to work at all and super slow). I finally tried Count.ly and WOW was I amazed at how well this simple mobile analytics tool works. Did I mention that it is open source with free optiions available?
Count.ly Analytics had a great iOS Analytics Module for Titanium Alloy in their documentation.
The Count.ly Android Analytics Module for Titanium Alloy was however not as great – it was outdated, had event count amount problems, database problems and did not include segmentation tracking functions – I created and update to the original and submitted a pull request – you can find my new updated Count.ly Android Module for Titanium Alloy on GitHub.
** UPDATE – I have since also added more updates, updating the SDKs to the latest Count.ly SDK and adding UserData support. I have also changed the Android module to use functions as the iOS module does – thus creating matching functions and eliminating the need for Platform Specific code.
Here is a basic iOS and Android use Example below:
1. Download the iOS and Android Count.ly Analytics Modules ZIPS for Titanium Alloy from the githubs
– Android- count.ly-android-0.1.2.zip – https://github.com/dieskim/Count.ly-Titanium-Android
– iOS -count.ly-iphone-0.3.2.zip – https://github.com/euforic/Titanium-Count.ly
Register your module with your application by editingtiapp.xml
and adding your module.
<modules> <module platform="iphone">count.ly</module> <module platform="android">count.ly</module> </modules>
Usage
Start Count.ly
Initialize Count.ly
var Countly = require('count.ly'); Countly.start('API_KEY','http://yourserver.com OR https://cloud.count.ly');
Record Events
Set any of the following Fields in an Object
var segmentation = {device:"iPhone 4S", country:"USA"}; var eventData = {name: "keySegmentationCountSum", segmentation:segmentation, count: 1, sum: 0.99};
- name (required) : Name of the event to track
- (example – Track clicks on the help button “clickedHelp” )
- count (required) : Number to increment the event in the db
- (example – User purchases item increment by 1 )
- sum : If the event is tied to an overall numerical data, such as a purchase, we can use sum to keep track of that
- (example – 0.99)
- segmentation : Categorization of the event
- (example – User is from USA and uses an iPhone 4S so the segmentation will be {device:”iPhone 4S”, country:”USA”} )
Track Events Examples
var segmentation = {device:"iPhone 4S", country:"USA"}; Ti.API.log("Send keyCount Event"); var eventData = {name: "keyCount", count: 1}; Countly.event(eventData); Ti.API.log("Send keyCountSum Event"); var eventData = {name: "keyCountSum", count: 1, sum: 0.99}; Countly.event(eventData); Ti.API.log("Send keySegmentationCount Event"); var eventData = {name: "keySegmentationCount", segmentation:segmentation, count: 1}; Countly.event(eventData); Ti.API.log("Send keySegmentationCountSum Event"); var eventData = {name: "keySegmentationCountSum", segmentation:segmentation, count: 1, sum: 0.99}; Countly.event(eventData);
Set UserData
Set any of the following Fields in an Object
*Set userData{} as information about user *Possible keys are:
- name – (String) providing user’s full name
- username – (String) providing user’s nickname
- email – (String) providing user’s email address
- organization – (String) providing user’s organization’s name where user works
- phone – (String) providing user’s phone number
- picture – (String) providing WWW URL to user’s avatar or profile picture
- picturePath – (String) providing local path to user’s avatar or profile picture
- gender – (String) providing user’s gender as M for male and F for female
- byear – (int) providing user’s year of birth as integer
var userData = { name: "testName", username: "testUsername", email: "testemail", organization: "testOrg", phone: "testPhone", picture: "https://count.ly/wp-content/uploads/2014/10/logo.png", picturePath: "/images/appicon.png", gender: "M", byear: "1980", };
*Set customUserData{} as information about user with custom properties *In customUserData you can provide any string key values to be stored with user
var customUserData = { key1: "value1", key2:"value2", };
*Set Userdata as set in userData and customData *Can contain both userData and customData – or just userdata
Ti.API.log("Set UserData"); var args = { userData:userData, customUserData:customUserData, }; Countly.userData(args);