Commit 902cf5f8 by Torkel Ödegaard

fix(): google analytics fix

parent bd010289
...@@ -141,6 +141,7 @@ func getFrontendSettingsMap(c *middleware.Context) (map[string]interface{}, erro ...@@ -141,6 +141,7 @@ func getFrontendSettingsMap(c *middleware.Context) (map[string]interface{}, erro
"authProxyEnabled": setting.AuthProxyEnabled, "authProxyEnabled": setting.AuthProxyEnabled,
"ldapEnabled": setting.LdapEnabled, "ldapEnabled": setting.LdapEnabled,
"alertingEnabled": setting.AlertingEnabled, "alertingEnabled": setting.AlertingEnabled,
"googleAnalyticsId": setting.GoogleAnalyticsId,
"buildInfo": map[string]interface{}{ "buildInfo": map[string]interface{}{
"version": setting.BuildVersion, "version": setting.BuildVersion,
"commit": setting.BuildCommit, "commit": setting.BuildCommit,
......
define([ define([
'angular', 'angular',
'../core_module', 'jquery',
'app/core/core_module',
'app/core/config',
], ],
function(angular, coreModule) { function(angular, $, coreModule, config) {
'use strict'; 'use strict';
coreModule.default.service('googleAnalyticsSrv', function($rootScope, $location) { coreModule.default.service('googleAnalyticsSrv', function($rootScope, $location) {
var first = true;
function gaInit() {
$.getScript('https://www.google-analytics.com/analytics.js'); // jQuery shortcut
var ga = window.ga = window.ga || function () { (ga.q = ga.q || []).push(arguments); }; ga.l = +new Date;
ga('create', config.googleAnalyticsId, 'auto');
return ga;
}
this.init = function() { this.init = function() {
$rootScope.$on('$viewContentLoaded', function() { $rootScope.$on('$viewContentLoaded', function() {
// skip first var track = { page: $location.url() };
if (first) {
first = false; var ga = window.ga || gaInit();
return;
} ga('set', track);
window.ga('send', 'pageview', { page: $location.url() }); ga('send', 'pageview');
}); });
}; };
}).run(function(googleAnalyticsSrv) { }).run(function(googleAnalyticsSrv) {
if (window.ga) {
if (config.googleAnalyticsId) {
googleAnalyticsSrv.init(); googleAnalyticsSrv.init();
} }
}); });
}); });
...@@ -91,18 +91,6 @@ ...@@ -91,18 +91,6 @@
<script src="[[.AppSubUrl]]/public/app/boot.js"></script> <script src="[[.AppSubUrl]]/public/app/boot.js"></script>
<!-- endbuild --> <!-- endbuild -->
[[if .GoogleAnalyticsId]]
<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','//www.google-analytics.com/analytics.js','ga');
ga('create', '[[.GoogleAnalyticsId]]', 'auto');
ga('send', 'pageview');
</script>
[[end]]
[[if .GoogleTagManagerId]] [[if .GoogleTagManagerId]]
<script> <script>
dataLayer = [{ dataLayer = [{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment