2017 © Pedro Peláez
 

symfony-bundle piwik-bundle

Symfony2 Bundle that adds a twig-function for the Piwik tracking code.

image

webfactory/piwik-bundle

Symfony2 Bundle that adds a twig-function for the Piwik tracking code.

  • Tuesday, May 22, 2018
  • by webfactory
  • Repository
  • 9 Watchers
  • 27 Stars
  • 60,439 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 11 Forks
  • 4 Open issues
  • 11 Versions
  • 3 % Grown

The README.md

webfactory Logo WebfactoryPiwikBundle

Run Tests Coverage Status, (*1)

A Symfony Bundle that helps you to use the Matomo (formerly known as Piwik) Open Analytics Platform with your project., (*2)

It contains a Twig function that can insert the tracking code into your website. Plus, you can turn it off with a simple configuration switch so you don't track your dev environment., (*3)

Installation

composer require webfactory/piwik-bundle

And enable the bundle in app/AppKernel.php:, (*4)

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Webfactory\Bundle\PiwikBundle\WebfactoryPiwikBundle(),
    );
}

Usage

Somewhere in your views, right before the closing </body> tag, insert, (*5)

{{ piwik_code() }}

This will add the appropriate Matomo tracking code as described in the API reference., (*6)

Configuration

You can configure the bundle in your config.yml. Full Example:, (*7)

webfactory_piwik:
    # Required, no default. Must be set to the site id found in the Matomo control panel
    site_id: 1
    # Required. no default. Hostname and path to the Matomo host.
    piwik_host: my.piwik.hostname
    # Optional, has default. Usually, you only want to include the tracking code in a production environment
    disabled: '%kernel.debug%'
    # Optional, has default. Path to the tracking script on the host.
    tracker_path: "/js/"
    # Optional, has default. Disable cookies in favor of GDPR
    # https://matomo.org/faq/new-to-piwik/how-do-i-use-matomo-analytics-without-consent-or-cookie-banner/ & https://matomo.org/faq/general/faq_157/
    disable_cookies: true

Add calls to the JavaScript tracker API

The JavaScript tracking API provides a lot of methods for setting the page name, tracking search results, using custom variables and much more., (*8)

The generic piwik() function allows you to control the _paq variable and add additional API calls to it. For example, in your Twig template, you can write, (*9)

    
    {{ piwik("setDocumentTitle", document.title) }}
    {{ piwik("trackGoal", 1) }}

    <!-- Then, at the end: -->
    {{ piwik_code() }}
    </body>

Note that when you call trackSiteSearch, this will automatically disable the trackPageView call made by default. This is the recommended behaviour., (*10)

This code was written by webfactory GmbH, Bonn, Germany. We're a software development agency with a focus on PHP (mostly Symfony). If you're a developer looking for new challenges, we'd like to hear from you!, (*11)

Copyright 2012 – 2020 webfactory GmbH, Bonn. Code released under the MIT license., (*12)

The Versions

23/12 2014

dev-public-twig-extension-service

dev-public-twig-extension-service

Symfony2 Bundle that adds a twig-function for the Piwik tracking code.

  Sources   Download

MIT

The Requires

 

The Development Requires