back to phpList.org

Add argument into link - For Matomo monitoring

Hi Everyone,

In this old topic, Chris A (end post) share a code to add automatically an argument for matomo (piwik) monitoring.

// URLs which are monitored by piwik
$my_webs = array(
      'burma-center.org',
      'dmsbambus.cz',
      'mikrogranty.cz'
   );

$target = $linkdata['forward'];

foreach($my_webs as $what) {
   if(strpos($target, $what)) {
      $target .= strpos($target, '?') ? '&' : '?';
      $target .= 'piwik_campaign=newsletter&piwik_kwd='.$messageid;
      break;
   }
}

header("Location: $target");

I’ve been read this documentation from matomo solution
Juste add “?” and argument piwik_campaign=test
For Exemple : https:// proserv .fr/informatique/?piwik_campaign=test

But, sometimes I’ve already an argument with “?” into my URL to monitor.
–> https:// proserv .fr/informatique/?service=sauvegarde

So, if I whant add matomo argument to this URL (for exemple), I do add an “&” instead of “?” Matomo argument.
–> https:// proserv .fr/informatique/?service=sauvegarde&piwik_campaign=test

The code above doesn’t check if argument already exist into URL.

My question : How I can add a condition to tack if an argument already exist ?

if ... {
// code here
} else {
// code here
}

Sorry for my english, and thanks for your support guys :wink:

Any idea for this question ?

You are misunderstanding the code. This looks for a ‘?’ character

strpos($target, '?')

So sorry.
All right, the condition exists.
Thanks, you’re opening my eyes.