I'd like to add some tracking javascript at the top of every page (a la Google Analytics or Piwik). This is either roughly or explicitly related to T6621, T6914, Q571, and T4213. It seems the current suggested way to do this is to maintain a fork of Phabricator that directly modifies either PhabricatorStandardPageView.php or PhabricatorBarePageView.php. We don't have a fork of Phabricator and have instead opted to extend it when we need additional functionality that doesn't exist in the upstream. I'd like to continue doing that if possible so I see a few options:
- I could add a config option called html.in-the-head-of-every-page which lets administrators insert any arbitrary HTML . PhabricatorStandardPageView would then read that config value and insert it at the top of every page. This has obvious security concerns as it would allow a malicious administrator to insert mean code at the top of every page and steal everyones' secrets.
- I could create an abstract PhabricatorThirdPartyAnalytics class (or something of that ilk) in the upstream that exposes a getTrackingHTML() function. Then PhabricatorStandardPageView would issue a PhutilClassMapQuery and insert the tracking HTML for each concrete subclass (which we'd write downstream). This would be safer than the config option as it would require server access to edit the javascript.
- I could build out a more third-party-aware Tracking/Analytics application that exposes config options like google.analytics-key or piwik.application-key and then it just knows what to do with that information for each application. This seems like a pretty intractable approach since google tells me there are ~4.7 million client-side analytics libraries:
- I could just get over it and fork Phabricator for that one little change, then pretend that the fork doesn't exist the next time someone asks me to make horrific changes to Phab. Then we'd likely want to just close this task as a duplicate of T4213.
I'm partial to approach #2 if that's something you'd be amenable to accepting upstream.