Documentation ¶
Overview ¶
Package gtm provides a way to generate Google Tag Manager snippets.
Usage as a server module:
func main() { modules := []module.Module{ gtm.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{ "GTMJSSnippet": gtm.JSSnippet(c.Context), "GTMNoScriptSnippet": gtm.NoScriptSnippet(c.Context), ... }) return nil }) ... }
templates/page.html:
<html> <head> {{.GTMJSSnippet}} ... </head> <body> {{.GTMNoScriptSnippet}} ... </body> </html>
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ModuleName = module.RegisterName("go.chromium.org/luci/server/gtm")
ModuleName can be used to refer to this module when declaring dependencies.
Functions ¶
func JSSnippet ¶
JSSnippet returns the GTM snippet to be inserted into the top of the page's HEAD as is.
If the ContainerID 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.
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 NoScriptSnippet ¶
NoScriptSnippet returns the GTM snippet that works in a no-script environment to be inserted into the top of the page's BODY as is.
If the ContainerID 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 { // ContainerID is the Google Tag Manager container ID to use like // "GTM-XXXXXX". // // Default is empty, meaning Google Tag Manager integration is disabled. ContainerID 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.