analytics-code.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. /**
  3. * Author: ExactMetrics team
  4. * Copyright 2018 ExactMetrics team
  5. * Author URI: https://exactmetrics.com
  6. * License: GPLv2 or later
  7. * License URI: http://www.gnu.org/licenses/gpl-2.0.html
  8. */
  9. ?>
  10. <?php if ( 0 == $data['ga_with_gtag'] ):?>
  11. <!-- BEGIN ExactMetrics v<?php echo GADWP_CURRENT_VERSION; ?> Universal Analytics - https://exactmetrics.com/ -->
  12. <script>
  13. (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  14. (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  15. m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  16. })(window,document,'script','<?php echo $data['tracking_script_path']?>','ga');
  17. <?php echo $data['trackingcode']?>
  18. </script>
  19. <!-- END ExactMetrics Universal Analytics -->
  20. <?php else:?>
  21. <!-- BEGIN ExactMetrics v<?php echo GADWP_CURRENT_VERSION; ?> Global Site Tag - https://exactmetrics.com/ -->
  22. <script async src="<?php echo $data['tracking_script_path']?>?id=<?php echo $data['uaid']?>"></script>
  23. <script>
  24. window.dataLayer = window.dataLayer || [];
  25. function gtag(){dataLayer.push(arguments);}
  26. gtag('js', new Date());
  27. <?php echo $data['trackingcode']?>
  28. if (window.performance) {
  29. var timeSincePageLoad = Math.round(performance.now());
  30. gtag('event', 'timing_complete', {
  31. 'name': 'load',
  32. 'value': timeSincePageLoad,
  33. 'event_category': 'JS Dependencies'
  34. });
  35. }
  36. </script>
  37. <!-- END ExactMetrics Global Site Tag -->
  38. <?php endif;?>