Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Use Piwik in your Mojolicious app

tree: ae0d90579c

Fetching latest commit…

Cannot retrieve the latest commit at this time

Readme.pod

Mojolicious::Plugin::Piwik - Use Piwik in Mojolicious

  # On startup
  plugin 'Piwik' => {
    url => 'piwik.khm.li',
    site_id => 1
  };

  # In Template
  %= piwik_tag

  # In controller
  my $json = $c->piwik_api('API.getPiwikVersion');

Mojolicious::Plugin::Piwik is a simple plugin for embedding Piwik Analysis in your Mojolicious app.

  # Mojolicious
  $app->plugin(Piwik => {
    url => 'piwik.khm.li',
    site_id => 1
  });

  # Mojolicious::Lite
  plugin 'Piwik' => {
    url => 'piwik.khm.li',
    site_id => 1
  };

  # Or in your config file
  {
    Piwik => {
      url => 'piwik.khm.li',
      site_id => 1
    }
  }

Called when registering the plugin. Accepts the following parameters:

URL of your Piwik instance.

The id of the site to monitor. Defaults to 1.

Activates or deactivates the embedding of the script tag. Defaults to true if Mojolicious is in production mode, defaults to false otherwise.

Token for authentication. Used only for the Piwik API.

All parameters can be set either on registration or as part of the configuration file with the key Piwik.

  %= piwik_tag
  %= piwik_tag 1
  %= piwik_tag 1, 'piwik.khm.li'

Renders a script tag that asynchronously loads the Piwik javascript file from your Piwik instance. Accepts optionally a site id and the url of your Piwik instance. Defaults to the site id and the url given when the plugin was registered.

  # In Controller - blocking ...
  my $json = $c->piwik_api(
    'Actions.getPageUrl' => {
      token_auth => 'MyToken',
      idSite => [4,7],
      period => 'day',
      date   => 'today'
    }
  );

  # ... or async
  $c->piwik_api(
    'Actions.getPageUrl' => {
      token_auth => 'MyToken',
      idSite => [4,7],
      period => 'day',
      date   => 'today'
    } => sub {
      my $json = shift;
      # ...
    }
  );

Sends a Piwik API request and returns the response as a hash or array reference (the decoded JSON response). Accepts the API method, a hash reference with request parameters as described in the Piwik API, and optionally a callback, if the request is meant to be non-blocking.

In addition to the parameters of the API reference, the following parameters are allowed:

The url of your Piwik instance. Defaults to the url given when the plugin was registered.

Boolean value that indicates a request using the https scheme. Defaults to false.

Boolean value that indicates a test request, that returns the created request url instead of the JSON response. Defaults to false.

idSite is an alias of site_id and defaults to the id of the plugin registration. Some parameters are allowed to be array references instead of string values, for example idSite and date (for ranges).

  my $json = $c->piwik_api(
    'API.get' => {
      site_id => [4,5],
      period  => 'range',
      date    => ['2012-11-01', '2012-12-01'],
      secure  => 1
    });

Currently the API requests always expect JSON, so it is not recommended for the ImageGraph API. The plugin is also limited to the Analysis API and lacks support for eCommerce tracking.

To test the plugin against your piwik instance, create a configuration file with the necessary information as a perl data structure in t/auth.pl and run make test, for example:

  {
    token_auth => '123456abcdefghijklmnopqrstuvwxyz',
    url => 'http://piwik.khm.li/',
    site_id => 1
  };

Mojolicious.

  https://github.com/Akron/Mojolicious-Plugin-Piwik

Copyright (C) 2012, Nils Diewald.

This program is free software, you can redistribute it and/or modify it under the same terms as Perl.

This plugin was developed for khm.li - Kinder- und Hausmärchen der Brüder Grimm.

Hey! The above document had some coding errors, which are explained below:

Unknown directive: =LIMITATIONS

Something went wrong with that request. Please try again.