How can I include any JS code in Phabricator
Event Timeline
Tried numerous ways to do so.
Always failed with it.
And if they actually work to get properly executed, all but the first frame in the main views stop working and load forever.
Also looking for an easy way to do this, without building too much code around it, and just inject it somewhere, where its run exactly once on the end of every single page.
So if there is an easy solution, I would be glad to know.
I have a script like:
<script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','https://www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-google-user-id-here', 'auto'); ga('send', 'pageview'); </script>
I have to put this inline, or for example put it in its own php file and then use something like:
<?php include_once("analyticstracking.php") ?>
I tried to add it to
/src/view/page/PhabricatorStandardPageView.php
Or better link: https://secure.phabricator.com/source/phabricator/browse/master/src/view/page/PhabricatorStandardPageView.php
If I for example put the script directly at the top, all subframes stop working.
Like this:
If I try to inject it into a phutil_tag it seems to be escaped to not work at all, or shows a box at the top stating:
"Unexpected Output:
<script>
...
"
And just spills out again what I tried to inject, but does not execute it.
I may have done something wrong there, but I assumed the "renderFooter()" function to be a good place to add my script part.
After this, I tried to look into the celerity requires, but they are a bit too complicated for me to understand, and I doubt I would be allowed to directly return display code form them.
So in theory it would be great to have some special footer block type, that allows pasting html/js into a textbox and this is 1:1 appended to the page footer.
For sure with a big red warning that this may destroy all security integrity and efforts, but at least for me its kinda hard to find an entry point for adding such a static code block I want on every page.
- Andy