I've just started in on an issue with a D8 site, currently running Civi 5.25 and Mosaico 2.5.

Emails sent using Mosaico with clickthrough tracking contain a mix of correct and incorrect URLs. If I add a URL to an image that has been placed in Mosaico, then that URLs get correctly converted to something like https://example.org/libraries/civicrm/extern/url.php?u=xxx&qid=yyy Embedding a URL into text in the body of the email, and/or using a button with a URL, they get converted to an incorrect link, of the form https://example.org/vendor/civicrm/civicrm-core/extern/url.php?u=xxx&qid=yyy - and clearly these links lead only to 404s.

If I construct a comparable email using the 'traditional' mailer then the resulting trackable URLs are all of the correct form.

So it looks like Mosaico is doing something weird in terms of constructing the paths for some, but not all trackable URLs.

I've looked at my settings for Directories and Resource URLs, and also looked at civicrm.settings.php and nothing is jumping out at me as being wrong.

I'm not too familiar with D8/Civi, and neither do I know much of the history of the site, other than that I've just updated Mosaico from 2.3x to 2.5 in an unsuccessful effort to resolve this issue.

Where is Mosaico getting the path data from? Why is it constructing some URLs that are fine, but others that are broken? Any clues gratefully received.


Drupal 8's architecture is different from most, and you probably know that there are two copies of some files - one in libraries and one in vendor. My guess is that Mosaico is getting the path to url.php through two different functions that give different results.

Open up your civicrm.settings.php and find the line that has CIVICRM_UF_BASEURL in it, and paste these three lines anywhere below that:

$civicrm_setting['URL Preferences']['userFrameworkResourceURL'] = CIVICRM_UF_BASEURL . '/libraries/civicrm/';
$civicrm_paths['civicrm.root']['url'] = CIVICRM_UF_BASEURL . '/libraries/civicrm/';
$civicrm_setting['domain']['userFrameworkResourceURL'] = CIVICRM_UF_BASEURL . '/libraries/civicrm/';

This should hopefully force Civi to always return the libraries folder when constructing URLs to the extern subfolder.

EDIT: Today I was troubleshooting a site that went from using the Roundearth install method to the civicrm-asset-plugin method, and I had to comment out these lines to get the site to work. I suspect Mosaico will be fine without these lines now that I've completely converted.

  • 1
    Worked like a charm. Thanks. – Graham Jan 18 at 20:07
  • Hooray! I actually just came back here to add this PR in case you were using URLs with tokens, which don't currently support tracking (but do with this patch). – Jon G - Megaphone Tech Jan 18 at 21:37
  • 1
    The other thing I would suggest is that you should check to see if you have the civicrm asset composer installed and use that as appropriate and also suggest changing the default extern url setting in Administer -> System Settings -> Url Settings to use the default router rather than the standalone scripts if you are on a version of CiviCRM that supports that. – Seamus Lee Jan 19 at 21:55
  • 1
    @Graham Note my edit above. – Jon G - Megaphone Tech Jan 28 at 17:43
  • @JonG-MegaphoneTech would this be the same issue if I'm seeing the same behaviour on WordPress? – Rose Lanigan Mar 7 at 19:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.