Tracking custom variables in mobile apps

Hi there,

i’m currently trying to track actions in my mobile app with Piwik. I use Titanium Mobile (same SDK they used to build the Piwik Mobile App) and Titanium.Network.HTTPClient to call piwik.php.

I kind of reverse engineered the HTTP request a normal browser would do and so far everything works fine.
However my custom variables (the _cvar part) are ignored.
I would like to track some information about the device and operating system. Does anyone know if this is possible?

Code below…

var now = new Date();
var piwikUrl = 'http://piwik.dagobah/piwik.php';
var piwikParams = {
	idsite: 1,
	rec: 1,
	action_name: 'init',
	h: now.getHours(),
	m: now.getMinutes(),
	s: now.getSeconds(),
	res: Titanium.Platform.displayCaps.platformWidth+'x'+Titanium.Platform.displayCaps.platformHeight,
		"1": ["appVersion", Titanium.App.version],
		"2": ["os", Titanium.Platform.osname],
		"3": ["osVersion", Titanium.Platform.osname+' '+Titanium.Platform.version],
		"4": ["model", Titanium.Platform.model+' (CPU:'+Titanium.Platform.processorCount+'/DPI:'+Titanium.Platform.displayCaps.dpi+')']

var xhr = Titanium.Network.createHTTPClient();
xhr.timeout = 2000; // request timeout in msecs'GET', piwikUrl); // set request method and url
xhr.send(piwikParams); // fire request with supplied get parameters

You will need to JSON encode the custom variables.

Also can you not use the piwik.js client in titanium maybe?

Thanks matt, JSON encoding (JSON.stringify) “_cvar” was the solution.

I don’t use the piwik.js at all, just sending a request to piwik.php via Titanium.Network.HTTPClient. Works great so far.
Going to improve it a bit and then maybe publish the source on github.

Ok that’s cool. What would be best would be that your client follows the exact API of the PHP Tracker client. This is similar to the Java client: Java Tracking Client V1 - · Issue #2172 · matomo-org/matomo · GitHub