sfPiwikPlugin - 1.0.5

Integrate Piwik web analytics into your symfony project.

You are currently browsing
the website for symfony 1

Visit the Symfony2 website

« Back to the Plugins Home


Forgot your password?
Create an account



advanced search
Information Readme Releases Changelog Contribute
Show source | Show as Markdown

Piwik Plugin

A drop-in plugin to add a Piwik tracker to your presentation layer. To use this plugin, you'll need to have a Piwik server installed and running.


  • Install the plugin

      symfony plugin:install sfPiwikPlugin
  • Add the sfPiwikFilter to your filter chain in filters.yml

    # insert your own filters here
      class: sfPiwikFilter
  • Configure your app.yml

        enabled:     on
        tracker_url: example.com/piwik/
        site_id:     1
    • tracker_url is where the Piwik server is located. Do not inlcude the protocol prefix (http://).

    • site_id is the ID of your site in the Piwik installation

Advanced Usage

  • Module/Action-level Configuration

    There are various Piwik attributes that can be set at the module or action level by configuring the module.yml file.

          # any of the optional params in app.yml can go here
          # this configures the entire module
            # any of the optional params in app.yml can go here
            # this configures a specific action within a module
  • Configurable Parameters

    Read the Javascript docs on the Piwik website for further details on these parameters.

    • insertion - Position of the tracking code within the HTML <body>. (default=bottom)

    • custom_data - Any value that will be sent in the data response var. You'd only use this if you've developed a custom Piwik plugin or are using one that requires this field be set.

    • document_title - Customize the page name displayed in Piwik.

    • domains - Consider a host an "alias" host and not record the links to this domain as "outlinks".

    • download_classes - Set classes to be treated as downloads (in addition to piwik_download).

    • download_extensions - Set list of file extensions to be recognized as downloads.

    • ignore_classes - Set classes to be ignored if present in link (in addition to piwik_ignore).

    • link_classes - Set classes to be treated as outlinks (in addition to piwik_link).

    • link_tracking_timer - Set delay for link tracking in milliseconds.

    • enable_link_tracking - Install link tracking on all applicable link elements. (default=on)

    • campaign_name - Set a campaign name.

    • campaign_keyword - Set a campaign keyword.

    • before_tracker_js - Javascript code to be executed immediately before the tracker is invoked.

    • after_tracker_js - Javascript code to be executed immediately after the tracker is invoked.

    • force - Forces tracker code to be inserted in the respose even if the request type is "not trackable". See sfPiwikTracker::isTrackable().

    • no_init - If true, JS tracker initialization code is not inserted in the response. This is automatically set to true if the force parameter is on and the current request is XHR.

  • Accessing the Tracker

    At some point, you might want to be able to access the tracker instance from your code to perform some complex things. Here's how you'd do that:

    class myActions extends sfActions
      public function executeIndex($request)
        // get the tracker instance from the context
        $tracker = sContext::getInstance()->get(sfPiwikTracker::NS);
        // you can get or set any of the optional parameters
        $tracker->setDocumentTitle("My Title");
  • Tracker Events

    Just before the tracker writes the Javascript to the response body, it fires an event to notify listeners of the last chance to modify tracker parameters. The event fired is piwik_filter.inserting.

    Read the Events section from the Symfony guide to understand how events work.