PHP API Not Working!

Hi

I just can’t get the API to work properly. I have written some code that has an array of search engine bots as REGEX and my code loops over them checking the current user agent. If the user agent is matched the code is meant to store a custom variable in Piwik called “BotName” and send the name of the visiting bot to piwik. So for example my array item may be:

‘Googlebot/([0-9.]{1,10})’ => ‘Google Bot’

which would match the Google Bot and is meant to save the custom varibale BotName = “Google Bot”. But actually nothing is getting stored in Piwik.

Lets say for this example piwik is site id 1 and located at http://domain.com/piwik

I cut the code right back to try work out this problem by removing my loop that checks the user agent and just manually storing Google Bot in the variable, but still, nothing is saved in Piwik.

Here is my code:

// load piwik
require_once “PiwikTracker.php”;

    $piwik = new PiwikTracker( $idSite = 1, 'http://domain.com/piwik/');
    
    $botname = 'Google';

    // get the requested url
    $uri = site_url() . $_SERVER['REQUEST_URI'];
    
  
    $piwik->setCustomVariable ( 1, 'BotName', $botname );
    $piwik->setUrl ( $url = $uri);
    $piwik->doTrackPageView('test');

AND NOTHING HAPPENS!

I also don’t understand why the documents tell me in the construct to parse the idSite like this, why can’t I just send the integer rather than $idSite = 1

The example is self documenting code. You can be more terse in your own code.

There’s a bot filter in core/Tracker/Visit.php. You’ll need to bypass (eg a plugin, or blanking the user agent and ip address).

Hi

Since i posted this I thought it was something like that, thanks for the confirmation ill look into it :slight_smile: