Le Tracking API di Piwik

La modalità standard di archiviazione dei dati in Piwik è l’uso del tag di Tracciamento in Javascript . Questo funziona bene per la maggior parte dei siti, quando inserire del codice Javascript nel footer della pagina non è un problema.

Ci sono però altri casi frequenti in cui Javascript non può essere usato: pagine di Ebay, di MySpace, oppure Applicazioni Software, o per iPhone o Android, siti web per dispositivi mobile, ecc.

In questi casi, potete usare modalità alternative per registrare i visitatori, le visite, le pagine e le conversioni dei Goal in Piwik:

  • Simple Image Tracker
  • Advanced Image Tracker
  • PHP Piwik Tracking API

Nella seguente stringa, sostituite {$IDSITE} con l’ID del vostro sito web Piwik, e sostituite http://www.example.org/piwik/ con l’URL del vostro Piwik.

Image Tracker code

The Image Tracker code can be used when Javascript is not allowed.

Some websites like MySpace or eBay will not allow users to add Javascript to their profile but accept HTML. In this case, you can still track visits with Piwik using the Image Tracker.
Note: the code doesn't use Javascript so Piwik will not be able to track some user information such as search keywords, referrers, screen resolutions, browser plugins and page titles.

<!-- Piwik Image Tracker -->
<img src="http://www.example.org/piwik/piwik.php?idsite={$IDSITE}&amp;rec=1" style="border:0" alt="" />
<!-- End Piwik -->

The following parameters can also be passed to the image URL:
  • rec - (required) The parameter &rec=1 is required to force the request to be recorded
  • idsite - (required) Defines the Website ID being tracked
  • action_name - Defines the custom Page Title for this page view
  • urlref - The Referrer URL: must be set to the referrer URL used before landing on the page containing the Image tracker. For example, in PHP this value is accessible via
    $_SERVER['HTTP_REFERER']
  • idgoal - The request will trigger the given Goal
  • revenue - Used with idgoal, defines the custom revenue for this conversion
  • and more! - There are many more parameters you can set beyond the main ones above. See the Tracking API documentation page.

Piwik Tracking API (Advanced users)

It is also possible to call the Piwik Tracking API using your favorite programming language.

The Piwik Tracking API allows to trigger visits (page views and Goal conversions) from any environment (Desktop App, iPhone or Android app, Mobile website, etc.).

We currently provide a PHP client to call the API from your PHP projects. If you would like to contribute a version of the client in another programming language (Python, Java, Ruby, Perl, etc.) please create a ticket in our developer area (please attach the client code to the ticket).

Follow these instructions to get started with the Tracking API:

  • Click here to download the file PiwikTracker.php
  • Upload the PiwikTracker.php file in the same path as your project files
  • Copy the following code, then paste it onto every page you want to track. <?php
    // -- Piwik Tracking API init --
    require_once "/path/to/PiwikTracker.php";
    PiwikTracker::$URL = 'http://www.example.org/piwik/';
    ?>
  • Choose a Tracking method, then paste the code onto every page you want to track.
    • Method 1: Advanced Image Tracker

      The client is used to generate the tracking URL that is wrapped inside a HTML <img src=''> code.
      Paste this code before the </body> code in your pages. <?php
      // Example 1: Tracks a pageview for Website id = {$IDSITE}
      echo '<img src="'. str_replace("&","&amp;", Piwik_getUrlTrackPageView( $idSite = {$IDSITE}, $customTitle = 'This title will appear in the report Actions > Page titles')) . '" alt="" />';
      // Example 2: Triggers a Goal conversion for Website id = {$IDSITE} and Goal id = 2
      // $customRevenue is optional and is set to the amount generated by the current transaction (in online shops for example)
      echo '<img src="'. str_replace("&","&amp;", Piwik_getUrlTrackGoal( $idSite = {$IDSITE}, $idGoal = 2, $customRevenue = 39)) . '" alt="" />';
      ?>

      The Advanced Image Tracker method is similar to using the standard Javascript Tracking code. However, some user settings are not detected (resolution, local time, plugins and cookie support).

    • Method 2: HTTP Request

      You can also query the Piwik Tracker API remotely via HTTP. This is useful for environment where you can't execute HTML nor Javascript.
      Paste this code anywhere in your code where you wish to track a user interaction. <?php
      $piwikTracker = new PiwikTracker( $idSite = {$IDSITE} );
      // You can manually set the visitor details (resolution, time, plugins, etc.)
      // See all other ->set* functions available in the PiwikTracker.php file
      $piwikTracker->setResolution(1600, 1400);

      // Sends Tracker request via http
      $piwikTracker->doTrackPageView('Document title of current page view');

      // You can also track Goal conversions
      $piwikTracker->doTrackGoal($idGoal = 1, $revenue = 42);
      ?>

PiwikTracker PHP Class API

Leggete la documentazione sulle API riguardo alla classe del PiwikTracker.

Informazioni ulteriori

Leggi anche queste FAQ collegate

    No comments have been added yet...

Lascia un Commento

Commento all'articolo