Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The LUCI Authors. All rights reserved. | |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | |
| 3 // that can be found in the LICENSE file. | |
| 4 | |
| 5 // Package analytics provides a standard way to store the Google Analytics | |
| 6 // tracking ID. | |
| 7 // | |
| 8 // Usage Example | |
| 9 // | |
| 10 // This analytics package provides a convenient way to configure an analytics | |
| 11 // ID for an app. To use, just call analytics.ID(c) and inject that ID | |
| 12 // into a template. | |
| 13 // | |
| 14 // import ( | |
| 15 // ... | |
| 16 // "github.com/luci/luci-go/server/analytics" | |
| 17 // ... | |
| 18 // ) | |
| 19 // | |
| 20 // func myHandler(c context.Context, rw http.ResponseWriter, r *http.Request, p httprouter.Params) { | |
| 21 // ... | |
| 22 // return templates.Args{ | |
| 23 // "AnalyticsID": analytics.ID(c), | |
|
Vadim Sh.
2016/08/26 21:55:05
add also
func Snippet(c context.Context) template
hinoka
2016/08/26 23:11:36
Done.
| |
| 24 // } | |
| 25 // } | |
| 26 // | |
| 27 // And in the base html: | |
| 28 // | |
| 29 // {{ if .AnalyticsID }} | |
| 30 // (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ | |
| 31 // (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o) , | |
| 32 // m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a, m) | |
| 33 // })(window,document,'script','https://www.google-analytics.com/analytics.js',' ga'); | |
| 34 // | |
| 35 // ga('create', '{{.AnalyticsID}}', 'auto'); | |
| 36 // ga('send', 'pageview'); | |
| 37 // {{ end }} | |
| 38 package analytics | |
| OLD | NEW |