Documentation ¶
Overview ¶
Package analytics provides a way to generate google analytics snippets.
Usage as a server module:
func main() { modules := []module.Module{ analytics.NewModuleFromFlags(), } server.Main(nil, modules, func(srv *server.Server) error { srv.Routes.GET("/", ..., func(c *router.Context) { templates.MustRender(c.Context, c.Writer, "page.html", templates.Args{ "GTagSnippet": analytics.GTagSnippet(c.Context), ... }) return nil }) ... }
templates/page.html:
<html> <head> {{.GTagSnippet}} ... </head> <body> ... </body> </html>
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ModuleName = module.RegisterName("go.chromium.org/luci/server/analytics")
ModuleName can be used to refer to this module when declaring dependencies.
Functions ¶
func NewModuleFromFlags ¶
NewModuleFromFlags initializes options through command line flags.
Calling this function registers flags in flag.CommandLine. They are usually parsed in server.Main(...).
func Snippet ¶
Snippet returns the analytics snippet to be inserted into the page's source as is.
Depending on the kind of the AnalyticsID configured (see module's Options):
- format G-XXXXXX-YY documented at https://developers.google.com/analytics/devguides/collection/gtagjs#install_the_global_site_tag will embed loading of "gtag.js"
If the AnalyticsID isn't configured, this will return an empty template so that it's safe to insert its return value into a page's source regardless.
Types ¶
type ModuleOptions ¶
type ModuleOptions struct { // Google Analytics measurement ID to use like "G-XXXXXX". // // Default is empty, meaning Google analytics integration is disabled. AnalyticsID string }
ModuleOptions contain configuration of the analytics server module.
func (*ModuleOptions) Register ¶
func (o *ModuleOptions) Register(f *flag.FlagSet)
Register registers the command line flags.