Skip to content

Commit 3bc4631

Browse files
committed
Only send Google Analytics data if analytics was loaded successfully
Prevent errors in local environment and if people are using blockers.
1 parent 60e1a9d commit 3bc4631

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

docs/source/_assets/js/nav.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ $.when($.ready).then(function() {
5252
}, '', href)
5353

5454
// Track on Google Analytics
55-
ga('set', 'page', href)
56-
ga('send', 'pageview')
55+
if (typeof(ga) === 'function') {
56+
ga('set', 'page', href)
57+
ga('send', 'pageview')
58+
}
5759
})
5860
})
5961

@@ -66,8 +68,10 @@ $.when($.ready).then(function() {
6668
$('#content').html(e.state.content)
6769

6870
// Track on Google Analytics
69-
ga('set', 'page', e.state.href)
70-
ga('send', 'pageview')
71+
if (typeof(ga) === 'function') {
72+
ga('set', 'page', e.state.href)
73+
ga('send', 'pageview')
74+
}
7175
}
7276
}
7377

0 commit comments

Comments
 (0)