Piwik

# open source web analytics

http://piwik.org/

Les articles publiés sur le site

  • The complete guide on tracking your websites and web apps into multiple Piwiks and how to do it easily & efficiently

    23 février 2017, par InnoCraftCommunity, Development

    Getting the tracking of your website and apps right is crucial to your success as you need to ensure the measured data is meaningful and correct. That’s why we, at InnoCraft, help our clients setting up their web tracking and digital measurement strategy. Some challenges include tracking your analytics data into multiple Piwik services as well as the tracking of single-page websites and web applications (covered in a previous article). In this blog post, we explain how to track your data into multiple Piwik websites correctly.

    Embedding the tracking code

    First of all you need to embed your JavaScript tracking code into your website or app as usual. If you haven’t done this yet: Log in to your Piwik, click on “Administration” in the top right and go to “Tracking Code”. There you have various options to adjust your tracking code to your needs.

    Tracking the same data into different websites

    Let’s assume you have set up the regular JavaScript tracking code and you want to track the same data into a second Piwik website. This second Piwik website can be either on the same Piwik installation or on a different Piwik. To do this, add the following line to your tracking code:

    _paq.push(['addTracker', 'https://$yourPiwikDomain/piwik.php', idSite]);

    It should look like this:

    var u = '//$yourPiwikDomain';
    _paq.push(['addTracker', u + '/piwik.php', var idSite = 2]); // adds an additional tracker
    _paq.push(['setSiteId', '1']); // configures your regular Piwik tracker
    _paq.push(['setTrackerUrl', u + 'piwik.php']);

    This will track the same data into website 1 and website 2 of your Piwik installation. You can also change the domain in addTracker to point it to a different Piwik installation:

    _paq.push(['addTracker', '//$differentPiwikDomain/piwik.php', var idSite = 2]);

    All Piwik tracker methods that you call afterwards will be applied to all trackers. Say you call _paq.push(['disableCookies']); _paq.push(['trackPageView']);, then both methods will be called on all tracker instances assuring they will behave the same and will track the same data into both Piwik websites.

    Tracking different data into different websites

    If you want to track only certain data into one website, and different data into an additional website, you need to configure the trackers differently. For example, you want to enable link tracking only for one tracker, but not for the other. The problem is that calling _paq.push(['enableLinkTracking']); enables link tracking on all of your trackers. To workaround this limitation, you can configure your trackers differently like this:

    window.piwikAsyncInit = function () {
        Piwik.on('TrackerSetup', function (tracker) {
          if (tracker.getSiteId() == 2 
             || tracker.getTrackerUrl() === '//$yourPiwikDomain/piwik.php') {
              tracker.enableLinkTracking();
    	}
        });
    };

    Now it enables link tracking only for the tracker that is configured for a certain website ID or Piwik domain.

    Accessing a previously generated tracker instance

    When you configure a tracker via _paq.push, you create a so called “Async tracker” because Piwik will be loaded asynchronously and create the tracker instance as soon as it is loaded. If you need to get the instance of such a tracker, you can use the method Piwik.getAsyncTracker(trackerUrl, idSite). This can be useful if you have a single-page website and want to track different data into different websites:

    window.addEventListener('hashchange', function() {
        if ('undefined' === typeof Piwik) {
            // Piwik might not be loaded yet
            return;
        }
        var tracker1 = Piwik.getAsyncTracker('//$yourPiwikDomain/piwik.php', var idSite = 1);
        var tracker2 = Piwik.getAsyncTracker('//$yourPiwikDomain/piwik.php', var idSite = 2);
        tracker1.setCurrentUrl('/' + window.location.hash.substr(1));
        tracker2.setCurrentUrl('/mywebsite/' + window.location.hash.substr(1));
    });

    Tracking different data into multiple Piwik installations without using “_paq”

    Some users prefer to not use _paq.push and instead directly create tracker instances themselves using the method Piwik.getTracker(trackerUrl, idSite) like this:

    window.piwikAsyncInit = function () {
        var tracker1 = Piwik.getTracker('//$yourPiwikdomain/piwik.php', var idSite = 1);
        tracker1.disableCookies();
        var tracker2 = Piwik.getTracker('//$yourPiwikdomain/piwik.php', var idSite = 2);
        tracker2.enableLinkTracking();
    
        tracker1.trackPageView();
        tracker2.trackPageView();
    };

    We usually don’t recommend creating trackers manually as it is more complicated and you need to make sure to configure trackers in the right order. For example to prevent the setting of any cookies, it is recommended to call disableCookies before calling any other methods. If you want to create your trackers manually and you use any of the following methods, make sure to call them in this order:

    disableCookies(), setAPIUrl(), enableCrossDomainLinking(), setCookiePath(), setCookieDomain(), setDomains(), setUserId(), enableLinkTracking()

    Roll-Up Reporting – the easy and efficient way

    Often users track data into multiple websites because they need aggregated data over all their websites. They want to see all statistics for a single website, but also which pages were viewed across all their websites, or how much traffic they got from a specific website or search engine across all websites. This means they add a second tracker to all their websites and track data not only into the regular Piwik website, but also into one additional website that gives them statistics over all websites. This has several disadvantages:

    • Complexity in getting the tracking code right and the time needed to integrate and maintain it
    • Slower website performance because everything needs to be tracked into several websites. This can decrease your conversions and sales
    • Slower Piwik performance because it has to handle twice as much traffic. This means tracking becomes slower, generating the report becomes slower, and the database gets twice as big

    Luckily, there is a better solution called Roll-Up Reporting. With Roll-Up Reporting, you can get aggregated data over all websites and / or for a group of websites without any of these disadvantages. It lets you create as many Roll-Ups as you wish and you can choose which websites’ data should be aggregated together into a new website.

    We had customers who were able to remove one Piwik tracker because of this feature which resulted in less server costs, a faster website, and a faster Piwik. On top of all these advantages, it also lets you view the Visitor Log, Real-time Map, and other widgets and reports across several websites.

    Questions?

    If you got any questions, please let us know and get in touch with us. You can find more information about the Piwik JavaScript tracker on the Piwik Developer Zone. There is a section dedicated to Multiple Piwik Trackers.

  • How to track single-page websites and web applications using Piwik Analytics

    21 février 2017, par InnoCraftCommunity, Development

    Single-page websites and web applications have become a standard over the last years. Getting the tracking of such websites and apps right is crucial to your success as you need to ensure the measured data is meaningful and correct. That’s why we, at InnoCraft, help our clients setting up their web tracking and measurement strategy. Some challenges our clients face are the tracking of single-page websites and web applications. We will cover this challenge in this post with a complete example at the bottom.

    Embedding the Tracking Code

    First you need to embed your JavaScript tracking code into your single-page website or web application as usual. To do this go to “Administration” in the top right in your Piwik, click on “Tracking Code” and adjust the tracking code to your needs.

    Tracking a New Page View

    The challenge begins when you need to track a new page view. A single-page app is different from a usual website as there is no regular new page load and Piwik cannot detect automatically when a new page is viewed. This means you need to let Piwik know whenever the URL and the page title changes. You can do this using the methods setCustomUrl and setDocumentTitle like this:

    window.addEventListener('hashchange', function() {
            _paq.push(['setCustomUrl', '/' + window.location.hash.substr(1)']);
            _paq.push(['setDocumentTitle', 'My New Title']);
            _paq.push(['trackPageView']);
    }

    Resetting previously set custom variables

    If you have set any Custom Variables in scope “page”, you need to make sure to delete these custom variables again as they would be attributed to the new page view as well otherwise. The following code requires Piwik 3.0.2:

    _paq.push(['deleteCustomVariables', 'page']);      
    _paq.push(['trackPageView']);

    Updating the generation time

    Next you need to update the generation time before tracking a new page view. Otherwise, the initial page generation time will be attributed to all of your subsequent pageviews.

    If you don’t load new content from the server when the page changes, simply set the value to zero:

    _paq.push(['setGenerationTimeMs', 0]);
    _paq.push(['trackPageView']);

    In case you load new content from the server, we recommend to measure the time it took to load this content (in milliseconds) and set the needed time:

    _paq.push(['setGenerationTimeMs', timeItTookToLoadPage]);
    _paq.push(['trackPageView']);

    Updating the referrer

    Depending on whether you want to track the previous page as a referrer for the new page view, you should update the referrer URL by setting it to the previous page URL:

    _paq.push(['setReferrerUrl', previousPageUrl]);
    _paq.push(['trackPageView']);

    Making Piwik Aware of New Content

    When you show a new page, your single-page DOM might change as well. For example, you might replace parts of your page with new content that you loaded from your server via Ajax. This means you need to instruct Piwik to scan the DOM for new content. We’ll now go over various content types (Videos & Audio, Forms, Links and Downloads, Content tracking).

    Video and Audio tracking

    If you use the Media Analytics feature to track your videos and audios, whenever a new page is displayed you need to call the following method:

    _paq.push(['MediaAnalytics::scanForMedia', documentOrElement]);

    When you don’t pass any parameter, it will scan the entire DOM for new media. Alternatively, you can pass an element to scan only a certain area of your website or app for new media.

    Form tracking

    If you use the Form Analytics feature to measure the performance of your online forms, whenever a new page is displayed you need to call the following method:

    _paq.push(['FormAnalytics::scanForForms', docuemntOrElement]);

    Where documentOrElement points either to document to re-scan the entire DOM (the default when no parameter is set) or you can pass an element to restrict the re-scan to a specific area.

    Link tracking

    Supposing that you use the link tracking feature to measure outlinks and downloads, Piwik needs to re-scan the entire DOM for newly added links whenever your DOM changes. To make sure Piwik will track such links, call this method:

    _paq.push(['enableLinkTracking']);

    Content tracking

    If you use the Content Tracking feature, whenever a new page is displayed and some parts of your DOM changes, you need to call this method :

    _paq.push(['trackContentImpressionsWithinNode', documentOrElement]);

    Where documentOrElement points either to document or an element similar to the other methods. Piwik will then scan the page for newly added content blocks.

    Measuring Single-Page Apps: Complete Example

    In this example we show how everything works together assuming you want to track a new page whenever a hash changes:

    var currentUrl = location.href;
    window.addEventListener('hashchange', function() {
        _paq.push(['setReferrerUrl', currentUrl]);
         currentUrl = '' + window.location.hash.substr(1);
        _paq.push(['setCustomUrl', currentUrl]);
        _paq.push(['setDocumentTitle', 'My New Title']);
    
        // remove all previously assigned custom variables, requires Piwik 3.0.2
        _paq.push(['deleteCustomVariables', 'page']); 
        _paq.push(['setGenerationTimeMs', 0]);
        _paq.push(['trackPageView']);
        
        // make Piwik aware of newly added content
        var content = document.getElementById('content');
        _paq.push(['MediaAnalytics::scanForMedia', content]);
        _paq.push(['FormAnalytics::scanForForms', content]);
        _paq.push(['trackContentImpressionsWithinNode', content]);
        _paq.push(['enableLinkTracking']);
    });

    Questions?

    If you have any questions or need help, please get in touch with us. You can find more information about the Piwik JavaScript tracker on the Piwik Developer Zone.

  • How Media Analytics for Piwik gives you the insights you need to measure how effective your video and audio marketing is – Part 2

    2 février 2017, par InnoCraftCommunity

    In Part 1 we have covered some of the Media Analytics features and explained why you cannot afford to not measure the media usage on your website. Chances are, you are wasting or losing money and time by not making the most out of your marketing strategy this very second. In this part, we continue showing you some more insights you can expect to get from Media Analytics and how nicely it is integrated into Piwik.

    Video, Audio and Media Player reports

    Media Analytics adds several new reports around videos, audios and media players. They are all quite similar and give you similar insights so we will mainly focus on the Video Titles report.

    Metrics

    The above mentioned reports give you all the same insights and features so we will mainly focus on the “Video Titles” report. When you open such a report for the first time, you will see a report like this with the following metrics:

    • “Impressions”, the number of times a visitor has viewed a page where this media was included.
    • “Plays”, the number of times a visitor watched or listened to this media.
    • “Play rate”, the percentage of visitors that watched or listened to a media after they have visited a page where this media was included.
    • “Finishes”, the percentage of visitors who played a media and finished it.
    • “Avg. time spent”, the average amount of time a visitor spent watching or listening to this media.
    • “Avg. media length” the average length of a video or audio media file. This number may vary for example if the media is a stream.
    • “Avg completion” the percentage of how much visitors have watched of a video.

    If you are not sure what a certain metric means, simply hover the metric title in the UI and you will get a detailed explanation. By changing the visualization to the “All Columns Table” in the bottom of the report, you get to see even more metrics like “Plays by unique visitors”, “Impressions by unique visitors”, “Finish rate”, “Avg. time to play aka hesitation time”, “Fullscreen rate” and we are always adding more metrics.

    These metrics are available for the following reports:

    • “Video / Audio Titles” shows you all metrics aggregated by video or audio title
    • “Video / Audio Resource URLs” shows you all metrics aggregated by the video or audio resource URL, for example “https://piwik.org/media.mp4”.
    • “Video / Audio Resource URLs grouped” removes some information from the URLs like subdomain, file extensions and other information to get aggregated metrics when you provide the same media in different formats.
    • “Videos per hour in website’s timezone” lets you find out how your media content is consumed depending on the hour of the day. You might realize that your media is consumed very differently in the morning vs at night.
    • “Video Resolutions” lets you discover how your video is consumed depending on the resolution.
    • “Media players” report is useful if you use different media players on your websites or apps and want to see how engagement with your media compares by media player.

    Row evolution

    At InnoCraft, we understand that static numbers are not so useful. When you see for example that yesterday 20 visitors played a certain media, would you know whether this is good or bad? This is why we always give you the possibility to see the data in relation to the recorded data in the past. To see how a specific media performs over time, simply hover a media title or media resource URL and click on the “Row Evolution” icon.

    Now you can see whether actually more or less visitors played your chosen video for the selected period. Simply click on any metric name and the chosen metrics will be plotted in the big evolution graph.

    This feature is similar to the Media Overall evolution graph introduced in Part 1, but shows you a detailed evolution for an individual media title or resource.

    Media details

    Now that you know some of the most important media metrics, you might want to look a bit deeper into the user behaviour. For example we mentioned before the “Avg time spent on media” metric. Such an average number doesn’t let you know whether most visitors spent about the same time watching the video, or whether there were many more visitors that watched it only for a few seconds and a few that watched it for very long.

    One of the ways to get this insight is by again hovering any media title or resource URL and clicking on the “Media details” icon. It will open a new popup showing you a new set of reports like these:

    The “Time spent watching” and “How far visitors reached in the media” bar charts show you on the X-Axis how much time each visitor spent on watching a video and how far in the video they reached. On the Y-Axis you see the number of visitors. This lets you discover whether your users for example jump often to the middle or end of the video and which parts of your video was seen most often.

    The “How often the media was watched in a certain hour” and “Which resolutions the media was watched” is similar to the reports introduced in Part 1 of the blog post. However, this time instead of showing aggregated video or audio content data, they display data for a specific media title or media resource URL.

    Segmented audience log

    In Part 1 we have already introduced the Audience Log and explained that it is useful to better understand the user behaviour. Just a quick recap: The Audience Log shows you chronologically every action a specific visitor has performed on your website: Which pages they viewed, how they interacted with your media, when they clicked somewhere, and much more.

    By hovering a media title or a media resource and then selecting “Segmented audience log” you get to see the same log, but this time it will show only visitors that have interacted with the selected media. This will be useful for you for example when you notice an unusual value for a metric and then want to better understand why a metric is like that.

    Applying segments

    Media Analytics lets you apply any Piwik segment to the media reports allowing you to dice your visitors or personas multiplying the value that you get out of Media Analytics. For example you may want to apply a segment and analyze the media usage for visitors that have visited your website or mobile app for the first time vs. recurring visitors. Sometimes it may be interesting how visitors that converted a specific goal or purchased something consume your media, the possibilities are endless. We really recommend to take advantage of segments to understand your different target groups even better.

    The plugin also adds a lot of new segments to your Piwik letting you segment any Piwik report by visitors that have viewed or interacted with your media. For example you could go to the “Visitors => Devices” report and apply a media segment to see which devices were used the most to view your media. You can also combine segments to see for example how often your goals were converted when a visitor viewed media for longer than 10 seconds after waiting for at least 20 seconds before playing your media and when they played at least 3 videos during their visit.

    Widgets, Scheduled Reports, and more.

    This is not where the fun ends. Media Analytics defines more than 15 new widgets that you can add to your dashboard or export it into a third party website. You can set up Scheduled Reports to receive the Media reports automatically via email or sms or download the report to share it with your colleagues. It works also very well with Custom Alerts and you can view the Media reports in the Piwik Mobile app for Android and iOS. Via the HTTP Reporting API you can fetch any report in various formats. The plugin is really nicely integrated into Piwik we would need some more blog posts to fully cover all the ways Media Analytics advances your Piwik experience and how you can use and dig into all the data to increase your conversions and sales.

    How to get Media Analytics and related features

    You can get Media Analytics on the Piwik Marketplace. If you want to learn more about this feature, you might be also interested in the Media Analytics User Guide and the Media Analytics FAQ.

    https://piwik.org/media.mp4
  • How Media Analytics for Piwik gives you the insights you need to measure how effective your video and audio marketing is – Part 1

    31 janvier 2017, par InnoCraftCommunity

    Do you have video or audio content on your website or in your app? If you answered this with yes, you should continue reading and learn everything about our Media Analytics premium feature.

    When you produce video or audio content, you are either spending money or time or often both money and time on your content in the hope of increasing conversions or sales. This means you have to know how your media is being used, when it is used, for how long and by whom. You can simply not afford not to know how this content affects your overall business goals as you are likely losing money and time by not making the most out of it. Would you be able to answer any of the above questions? Do you know whether you can justify the cost and time for producing them, which videos work better than others and how they support your marketing strategy? Luckily, getting all these insights is now so trivial it is almost a crime to not measure it.

    Getting Media Analytics and Installation

    Media Analytics can be purchased from the Piwik Marketplace where you find all sorts of free plugins as well as several premium features such as A/B Testing or Funnel. After the purchase you will receive a license key that you can enter in your Piwik to install and update the plugin with just one click.

    The feature will in most cases automatically start tracking your media content and you don’t even need to change the tracking code on your website. Currently supported players are for example YouTube, Vimeo, HTML 5, JW Player, VideoJS and many more players. You can also easily extend it by adding a custom media player or simply by letting us know which player you use and we will add support for it for you.

    By activating this feature, you get more than 15 new media reports, even more exportable widgets, new segments, APIs, and more. We will cover some of those features in this blog post and in part 2. For a full list of features check out the Media Analytics page on the Piwik Marketplace.

    Media Overview

    As the name says, it gives you an overview over your media usage and how it performs over time. You can choose any media metrics in the big evolution graph and the sparklines below give you an overview over all important metrics in a glance.

    It lets you for example see how often media was shown to your users, how often users start playing your media, for how long they watched it, how often they finished it, and more. If you see some spikes there, you should definitely have a deeper look at the other reports. When you hover a metric, it will show you a tooltip explaining how the data for this is collected and what it means.

    Real-Time Media

    On the Real-Time page you can see how your content is being used by your visitors right now, for example within the last 30 minutes, last 60 minutes and last 24 hours.

    It shows you how many plays you had in the last minutes, for how long they played it, and it shows you currently most popular media titles. This is great to discover which media content performs best right now and lets you make decisions based on user behaviour that is happening right now.

    Below you can see our Audience Real-Time Map that shows you from where in the world your media is being played. A bigger circle indicates that a media play happened more recently and of course you can zoom in down to countries and regions.

    All the reports update every few seconds so you can always have a look at it and see in just a second how your content is doing and how certain marketing campaigns affect it. All these real-time reports can be also added as widgets to any of your Piwik Dashboards and they can be exported for example as an iframe.

    Video, Audio and Media Player reports

    Those reports come with so many features, we need a separate blog post and cover this in part 2.

    Events

    Media Analytics will automatically track events so you can see how often users pressed for example play or pause, how often they resumed a video and how often they finished a video. This helps you better understand how your media is being used.

    For example in the past we noticed a couple of videos with lots of pause and resume events. We then had a look at the Audience Log – which we will cover next – to better understand why visitors paused the videos so often. We then realized they did this especially for videos that were served from a specific server and because the videos were loading so slow, users often pressed pause to let the media buffer, then played the media for a few seconds and then paused it again as they had to wait for the video to load. Moving those videos to another, faster server showed us immediate results in the number of pauses going down and on average visitors watched the videos for much longer.

    Audience Log

    At InnoCraft, we understand that not only aggregated metrics matter but also that you often need the ability to dig into your data and “debug” certain behaviours to understand the cause for some unusual high or low metrics. For example you may find out that many of your users often pause a video, then you wonder how each individual user behaved so you can better understand the why.

    The audience log shows you a detailed log of every visitor. You can chronologically see every action a visitor has performed during their whole visit. If you click on the visitor profile link, you can even see all visits of a specific visitor, and all actions they have ever performed on your website.

    This lets you ultimately debug and understand your visitors and see exactly which actions they performed before playing your media, which media they played, how they played your media, and how they behaved after playing your media.

    The visitor log of course also shows important information about each visitor like where they came from (referrer), their location, software, device and much more information.

    Audience Map

    The Audience Map is similar to the Real-Time Map but it shows you the locations of your visitors based on a selected date range and not in real time. The darker the blue, the more visitors from that country, region or city have interacted with your media.

    Coming in part 2

    In the next part we will cover which video, audio and media player reports Media Analytics provides, how segmenting gives you insights into different personas, and how nicely it integrates into Piwik.

    How to get Media Analytics and related features

    You can get Media Analytics on the Piwik Marketplace. If you want to learn more about this feature, you might be also interested in the Media Analytics User Guide and the Media Analytics FAQ.

  • 3 hidden Piwik features you likely don’t know, that will make you more productive

    17 janvier 2017, par InnoCraftCommunity

    At Piwik and at InnoCraft, we always aim to make features as intuitive as possible. Having thousands of features in Piwik and having to find a balance between beginners and advanced users can sometimes be a challenge. Sometimes this even leads to building hidden features that are mainly targeted for power users. The list below shows three of them, did you know any of them yet?

    BTW: If you don’t have Piwik yet, you can try them on our Piwik Demo.

    1. Search

    When you press the letter “f”, it will activate the search bar in the top left. Once you start typing something, it will show matching reports. Say you want to view reports about “devices” but don’t remember exactly which category it is in, simply start typing “devices” and the matching entry will show up without even having to move the mouse.

    The search bar also searches for matching websites and segments. Use the arrow up and down keys to select the entry you want and press enter to confirm the selection.

    Say you don’t remember the name of a report but you know it is listed under the category “Visitor”, then start typing the name of the category and it will show all related reports.

    2. Zen Mode

    When you press the letter “z”, it will activate the Zen Mode which lets you focus on the reports and content by removing the header and left menu. To disable the Zen Mode, simply press “z” again.

    This is especially useful in combination with the search bar mentioned above, as it enables you to quickly switch between reports, websites and segments even while menu and header are hidden.

    3. Faster period change

    Changing the displayed period is a task you likely perform quite often when analyzing reports. Usually, you would first select the period and then press the button “Apply” in the date selector. Instead, you can simply double click the name of the period and it will immediately load the selected period without having to click on the “Apply” button.

    What are your hidden features in Piwik?

    Let us know by getting in touch with us or share it with us on Facebook or Twitter.