Plugin that modifies all widget query strings?

I am writing my first Piwik plugin. Its purpose is to force every widget on the site to have a particular “segment” parameter in its URL (if none exists already). So all URLs of the form:

would automatically become (for example):…&segment=pageTitle!=Home

What is the correct hook that lets me access this information and modify it? I tried the hook Controller.renderView, which provides me with a ViewDataTable object, but I could not figure out how to modify the URL or API call from here.

Given the correct hook, I am hoping this plugin will take only a few lines to write, looking something like this:

class Piwik_MyStuff extends Piwik_Plugin {

  public function getListHooksRegistered() {
    return array( 'The.Right.Hook' => 'MyCallback' );

  function MyCallback($x) {
    $stuff = $x->getTheNeededStuff();        // Magic. :-)
    $stuff['segment'] = 'pageTitle!=Home';

Any advice on how to implement this?

Thank you very much.

That’s a good suggestion. Have you tried $_GET[‘segment’] =$yourSegment; ?

I didn’t try that because I figured it was too late – by the time you have a ViewDataTable, the query string might already have been processed into some other form. But I’ll give that a try and let you know.

It works for some widgets like “Last Visitors Graph” and “Visitor Browsers,” but not others like “Entry Pages”. Do I need a different hook?

Thanks for the suggestion.

I added a new hook “FrontController.dispatch” in:

See example to use it:

function getListHooksRegistered()
		return array(
			'Menu.add' => 'addMenu',
			'FrontController.dispatch' => 'forceSegmentParameter',
	function forceSegmentParameter($notification)
//		$params = array($controller, $action, $parameters);
		$params = &$notification->getNotificationObject();
		$segment = 'country==FR';
		$params[2]['segment'] = $segment;
		$_GET['segment'] = $segment;