Tracking Tapatalk users with Piwik (Update)


Piwik is a nice open-source, self hostable tracking system like Google Analytics. It lists all the standart information like user browser, os, referral and associated metrics.

For the iPod-Forum i use this systems to get a chronological overview of the usage. I also use the integration of Tapatalk to get an optimized view for mobile users on iOS, Andorid and other mobile OS. What i missed is an integration of Tapatalk into the Piwik analytic tool, so i did it by myself.

All additional Code is used on your own risk! I used Piwik 1.12 to test it.

Tapatalk useragent
Thats the main problem. I hoped to get the mobile device out of the Tapatalk http useragent. I logged the useragents for a few hours, and received a lot of different agents:

Mozilla/5.0 Firefox/3.5.6 Tapatalk 2/2.0.3
Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3 Tapatalk/1.16.0
Mozilla/5.0 Firefox/3.5.6 Tapatalk/
Mozilla/5.0 Firefox/3.5.6
Mozilla/5.0 Firefox/3.5.6 Tapatalk/2.4.10

There is just one version of tapatalk that sets the iPhone as device in useragent. The reason is the compatibility with common webservers according to Tapatalk developers. So I’m not 100% able to get the used deviced, but I’m able to filter the Tapatalk users out of the visitors using the useragent.

Adding functions to piwik system
First you have to add the Tapatalk useragent to the Useragent parser

class UserAgentParser
{
	// browser regex => browser ID
	// if there are aliases, the common name should be last
	static protected $browsers = array(
        [...]
        // Dolfin (or Dolphin)
        'dolfin' => 'DF',
        //Tapatalk
        'tapatalk' => 'TT',
        // Firefox (in its many incarnations and rebranded versions)
        'phoenix' => 'PX',
        [...]

It is important to add the Tapatalk agent before the firefox agent, because Tapatalk includes the Firefox agent for compatibility reasons. If you parse the Tapatalk agent after Firefox, all the Tapatalk users count as Firefox users.

Next we add Tapatalk as a new Browser family:

// browser family (by layout engine)
static protected $browserType = array(
  [...]
  'opera'  => array('OP'),
  'tapatalk' => array('TT'),
);

Last file we need to edit contains the user settings. We map the short code to a displayable name

/*
 * Mapping between the browser family shortcode and the displayed name
 */
static public $browserType_display = array(
  [...]
  'opera'  => 'Presto (Opera)',
  'tapatalk' => 'Tapatalk mobile forum client',
);

Now Piwik parses the useragent for tapatalk-string and will mark the browser then with the TT-shortcode. To visualise the Tapatalk users we need to add an icon for the Tapatalk-users. You can use this one and add it to piwik/plugins/UserSettings/images/browsers/TT.gif

Tapatalk icon

Add tracking code to Tapatalk

You need to use the Piwik API to track the Tapatalk users. First of all you need the tracking class provided by Piwik. You can Download piwikTracker.php here:

[button type=“primary“ size=“small“ text=“Piwik API documentation“ url=“http://piwik.org/docs/tracking-api/#toc-piwik-tracking-api-advanced-users“]

Now we edit the Tapatalk server side script the script depends on your forum system so just the tracking code is displayed here

Update 02.01.2014:
– Added fix for Tapatalk useragent without Version (will be 1.0)
– Added $piwikTracker->setBrowserHasCookies(false);

//Include the piwikTracker.class downloaded from piwik.org
@require_once('./mobiquo/lib/piwikTracker.class.php');

//Set the piwik-url
PiwikTracker::$URL = 'http://piwik.example.com';

//The site-id for this website
$piwikTracker = new PiwikTracker( $idSite = 1 );

//Piwik token auth (see piwik panel -> API)
$piwikTracker->setTokenAuth('myexampletoken');

//Set the user IP (if not set, server IP will be used)
$piwikTracker->setIp($_SERVER['REMOTE_ADDR']);

//Change the Tapatalk useragent
$version = str_replace('Mozilla/5.0 Firefox/3.5.6 ','',$_SERVER['HTTP_USER_AGENT']);

//Fix if useragent doesn't contain Version of Tapatalk
if(substr($version,-1,1) == '/')
  $version = $version.'1.0';

$piwikTracker->setUserAgent($version);

$piwikTracker->setBrowserHasCookies(false);

//Get the tapatalk function used and fire the tracking
$request_method_name = get_method_name();
$piwikTracker->doTrackPageView('Tapatalk - '.$request_method_name);

Thats it. The result looks like this

Tapatalk user in Piwik log

Tapatalk in browser list


2 Gedanken zu “Tracking Tapatalk users with Piwik (Update)

  • David

    Hello ! I would like to do like you with a kunena forum.
    I’ve done all you said but it doesn’t work 🙁
    Can you help me?
    Thnak you

  • Fel1x

    I’m not common with kunena, but at a first look you need to change the mobiquoCommon.php like this:

    http://pastebin.com/C1UJ8AFR

    remember to add the piwikTrack-Class to mobiquo directory and change the needed variables in mobiquoCommon.php for URL, Site-ID and API-Token

Kommentare sind geschlossen.