In this example I append an extra argument to the Mailpoet tracker url called uidhash. This happens to be the confirmation hash used by Mailpoet. The hook should be added to functions.php
.
function my_tracker_replaceusertags($email,$user){
$urls = array();
$results = array();// collect all links in email
if(!preg_match_all('#href[ ]*=[ ]*"(?!mailto:|\#|ymsgr:|callto:|file:|ftp:|webcal:|skype:)([^"]+)"#Ui',$email->body,$results)) return;
foreach($results[1] as $i => $url){
if(isset($urls[$results[0][$i]])|| strpos($url, 'wysija-key')) continue;
$urls[$results[0][$i]] = str_replace($url,$url . '&uidhash=' . $user->keyuser,$results[0][$i]);
}
$email->body = str_replace(array_keys($urls),$urls,$email->body);
}
add_action('wysija_replaceusertags', my_tracker_replaceusertags,12,2);