I have created a token using hook_civicrm_tokenValues that inserts content into a CiviMail. The content includes URLs that we want to track.
As I understand it (and I don't understand it very well) in CiviMail, token substitution happens after links have been converted to trackable urls, which means that any links that are inserted into tokens will not / cannot be tracked.
I'm wondering what the smartest way to get around this is?
Options I am considering are:
1) run the relevant CRM_Mailing_BAO_TrackableURL functions again once the tokens have been subsituted and observing if there are any side effects (maybe some stuff coming from other tokens should not be tracked). FWIW, it looks like CRM_Mailing_BAO_TrackableURL::getTrackerURL() already takes some steps to not track links in the format civicrm/extern/
which would cover links like civicrm/extern/url.php?u=129&qid=77
.
// hack for basic CRM-1014 and CRM-1151 and CRM-3492 compliance:
// let's not replace possible image URLs and CiviMail ones
if (preg_match('/\.(png|jpg|jpeg|gif|css)[\'"]?$/i', $url)
or substr_count($url, 'civicrm/extern/')
or substr_count($url, 'civicrm/mailing/')
) {
// let's not cache these, so they don't get &qid= appended to them
return $url;
}
2) switch the order of execution so that token substitution happens before links have been converted to trackable urls (but there may important reasons why it happens in that particular order).
3) create trackable URLs as part of the token generation though I wonder if I would be able to access the data I need for the appropriate CRM_Mailing_BAO_TrackableURL function at this point and if the function is expecting to be called in a certain context.
hook_civicrm_tokenValues
? I'm not sure if I follow your questionCRM_Mailing_BAO__TrackableURL::getTrackerURL()
withinhook_civicrm_tokenValues
, if you are in the Mailing context the job id is available and you can get the rest of required params to build the trackable URLs, not for standalone email though, and I don't know about SMS