We are looking to add Google Analytics Tracking codes to the header of the Jira Install, but in very specific places. Right now we have the tracking code installed in the “announcements bar” area which works fine for tracking users and other metrics. It does not however work for page load times as it is being loaded too late in the DOM.
In order to gather more accurate metrics as well as extend the metrics to give us better insights into performance benchmarking we need to load a script right after the opening and another right before the closing tag. What is the best way to do this?
Here is the code that we are trying to inject
<head>
<script>
! function() {
if ('PerformanceLongTaskTiming' in window) {
var g = window.__tti = {
e: []
};
g.o = new PerformanceObserver(function(l) {
g.e = g.e.concat(l.getEntries())
});
g.o.observe({
entryTypes: ['longtask']
})
}
}();
</script>
and before the closing
<script type="text/javascript" src="[location-URL]/tti-polyfill.js"></script>
<script> ttiPolyfill.getFirstConsistentlyInteractive().then(console.log);
ttiPolyfill.getFirstConsistentlyInteractive().then((tti) => {
if (tti > 1) {
gtag('event', 'timing_complete', {
'name': 'TTI',
'value': tti,
'event_category': 'Page Speed'
});
}
});
</script>
</head>
Some notes:
- Environment is Jira Data Center
- Add-on https://marketplace.atlassian.com/apps/1217993/google-analytics-matomo-others is not available for DC yet
- Bug https://jira.atlassian.com/browse/JRASERVER-59587 requires editing multiple files
Any thoughts on how can we achieve this?