Add Google Analytics to OSTicket
To add Google Analytics to OSTicket sounds a daunting task but in reality it is fairly straightforward providing you know a small amount of HTML and or PHP and are able to login to your FTP Server.
This guide will presume that you already have a Google Analytics account and have created a new site property for your OSTicket installation.
Setup User-ID Tracking
You will also need to enabled the User-ID tracking feature of Google Analytics if you wish to track internal users of the system.
Edit files for staff analytics
You will need to edit the file /scp/tickets.php, this file handles all tickets related actions on the site and is used to pull ticket and queue information when a staff user requests it.
From my testing adding the Google Analytics code to the bottom of the page is sufficient to track every interaction a user has with the SCP side of the site
The standard code Google give you will be enough to track Anonymous access to the site but you can edit this to include the additional line below that will track logged in staff users by the means of echoing out their username to the tracking code.
<?php echo $thisstaff->getFirstName() ?>
Copy the below code ?> included at the very bottom of the tickets.php file and click save.
?>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=YOUR_TRACKING_CODE"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('set', {'user_id': '<?php echo $thisstaff->getFirstName() ?>'});
gtag('config', 'YOUR_TRACKING_CODE');
</script>
Edit files for client anayltics
To enable client analytics simply edit the file /include/client/header.inc.php to include the standard tracking code as below right after the HTML <head> section
<head>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=YOUR_TRACKING_CODE"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'YOUR_TRACKING_CODE');
</script>
Check its working
You should be able to check it is working from the Google Analytics homepage by simply looking on your dashboard and noting any new traffic.
Staff user tracking can be found under Audience and User Explorer, from here you will be able to see the journey the staff member has taken through the site and the tickets they have worked on.
By clicking on a user you can then drill down further to see the individual tickets they have visited.
Cheers for this, Guy, we’re fairly new to OSTicket & even newer still to the Awesome theme. I’m on cup one of the day & this helped me not have to think 😂
Glad this has helped you out Jeff.
Dan
If you’re interested Jeff I also do a reporting script for OSTicket here https://www.theictguy.co.uk/osticket-advanced-reporting-with-ostreports/
Hi,
I wanted to add the google analytics to the osticket that we are currently using. Would it be possible for us to have a call regarding it
Sorry, not able to take a phone call but happy to converse on comments.