analytics

package
v0.0.0-...-128afb8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 30, 2024 License: Apache-2.0 Imports: 7 Imported by: 4

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

View Source
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

func NewModuleFromFlags() module.Module

NewModuleFromFlags initializes options through command line flags.

Calling this function registers flags in flag.CommandLine. They are usually parsed in server.Main(...).

func Snippet

func Snippet(ctx context.Context) template.HTML

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):

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL