Skip to content

Commit 76ef33d

Browse files
authored
Merge pull request #91 from web-animations/analytics
analytics support for demos
2 parents 67194bb + ddd6573 commit 76ef33d

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

index.html

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -410,23 +410,25 @@ <h3>{{demo.name}}</h3>
410410
},
411411
hashchange: function() {
412412
var hash = window.location.hash;
413+
var demo = null;
413414
if (hash) {
414415
for (var i = 0; i < this.model.length; i++) {
415-
var demo = this.model[i];
416-
if (demo.hash == hash) {
417-
this.selected = demo;
418-
this.selectedHash = demo.hash;
419-
this.iframeURL = demo.path;
420-
this.setTitle(demo);
421-
return;
416+
if (this.model[i].hash == hash) {
417+
demo = this.model[i];
418+
break;
422419
}
423420
}
424421
}
425422

426-
this.selected = null;
427-
this.selectedHash = '';
428-
this.iframeUrl = '';
429-
this.setTitle(null);
423+
if (this.selected != demo && window.ga) {
424+
ga('set', 'page', window.location.pathname + window.location.hash);
425+
ga('send', 'pageview');
426+
}
427+
428+
this.selected = demo;
429+
this.selectedHash = demo ? demo.hash: '';
430+
this.iframeURL = demo ? demo.path : '';
431+
this.setTitle(demo);
430432
},
431433
setTitle: function(demo) {
432434
if (demo) {
@@ -473,5 +475,13 @@ <h3>{{demo.name}}</h3>
473475

474476
document.querySelector('web-animations-demos').model = demos;
475477
</script>
478+
<script>
479+
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
480+
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
481+
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
482+
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
483+
ga('create', 'UA-82759618-1', 'auto');
484+
ga('send', 'pageview');
485+
</script>
476486
</body>
477487
</html>

0 commit comments

Comments
 (0)