@mattab opened this Issue on October 2nd 2014 Member

The goal of this issue is to let Piwik Super Users configure a custom JavaScript snippet of code that would automatically be appended to the/piwik.js tracking code served by the Piwik tracking server(s).

Proposed solution

  • we build a new plugin "CustomPiwikJs"
  • this plugin would be open source and available in the Marketplace,
  • Super User can enter a JS code snippet in the CustomPiwikJs plugin setting Textarea,
  • the plugin defines a new console command that when executed will:
    • generate a new piwik.js appending any custom script,
    • if the generated piwik.js is different from the original /piwik.js
    • then overwrite the /piwik.js file.
  • appending JS script to piwik.js could be easily made available to
    other plugins via a hook.
    • This would lead to amazing potential for plugins to customise the tracking code served by Piwik to the websites and web apps!
    • eg. plugin Heatmap #6371 could require CustomPiwikJs plugin and then insert custom JS tracker to store mouse positions and build heatmaps


  • this logic would be executed as schedule task every 5 min or so if possible, and also once after each Piwik Upgrade.
  • to make sure our sync task runs really every 5 min, we will need to setup a cron for user to execute this command every 5 minutes:
    core:run-scheduled-tasks Will run all scheduled tasks due to run at this time.
  • (if the last scheduled task ran more than N min ago, display a warning message notification that file may be out of sync)

feel free to post if you have any feedback!

@mnapoli commented on October 13th 2014 Contributor

When to update the file:

  • On update in the admin panel
  • Daily
  • Piwik update event
  • Plugin enable/disable event

Warning in the readme for load-balanced setups.

@mnapoli commented on October 14th 2014 Contributor

See #6440

@mattab commented on October 14th 2014 Member

The plugin is already available on the Marketplace! http://plugins.piwik.org/CustomTrackerJs

@mattab commented on October 17th 2014 Member

Well done @mnapoli

@mattab commented on October 21st 2014 Member
This Issue was closed on October 17th 2014
Powered by GitHub Issue Mirror