Skip to content

Commit

Permalink
tour: add analytics HTML and deploy instructions
Browse files Browse the repository at this point in the history
When deployed with App Engine on tour.golang.org,
insert analytics HTML at the beginning of <head>.

Add deploy instructions to the README.

Also update to the App Engine Go 1.12 runtime.

Change-Id: Ib3333290783f34eb00843006cf949308302b342d
Reviewed-on: https://go-review.googlesource.com/c/tour/+/198320
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
  • Loading branch information
dmitshur committed Oct 2, 2019
1 parent 45121ac commit 6bb846c
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 5 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,24 @@ The main issue tracker for the tour is located at
https://github.com/golang/go/issues. Prefix your issue with "tour:" in the
subject line, so it is easy to find.

## Deploying

1. To deploy tour.golang.org, run:

```
GO111MODULE=on gcloud --project=golang-org app deploy --no-promote app.yaml
```

This will create a new version, which can be viewed within the
[golang-org GCP project](https://console.cloud.google.com/appengine/versions?project=golang-org&serviceId=tour).

2. Check that the deployed version looks OK (click the version link in GCP).

3. If all is well, click "Migrate Traffic" to move 100% of the tour.golang.org
traffic to the new version.

4. You're done.

## License

Unless otherwise noted, the go-tour source files are distributed
Expand Down
11 changes: 10 additions & 1 deletion app.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
service: tour
runtime: go111
runtime: go112

env_variables:
GOLANGORG_CHECK_COUNTRY: true
TOUR_ANALYTICS: |
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-11222381-5"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag("js", new Date());
gtag("config", "UA-11222381-5");
gtag("config", "UA-49880327-6");
</script>
default_expiration: "7d"

Expand Down
2 changes: 2 additions & 0 deletions appengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package main
import (
"bufio"
"bytes"
"html/template"
"io"
"log"
"net/http"
Expand All @@ -18,6 +19,7 @@ import (
func gaeMain() {
prepContent = gaePrepContent
socketAddr = gaeSocketAddr
analyticsHTML = template.HTML(os.Getenv("TOUR_ANALYTICS"))

if err := initTour(".", "HTTPTransport"); err != nil {
log.Fatal(err)
Expand Down
4 changes: 4 additions & 0 deletions local.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"flag"
"fmt"
"go/build"
"html/template"
"io"
"log"
"net"
Expand Down Expand Up @@ -224,3 +225,6 @@ var prepContent = func(r io.Reader) io.Reader { return r }

// socketAddr returns the WebSocket handler address.
var socketAddr = func() string { return "ws://" + httpAddr + socketPath }

// analyticsHTML is optional analytics HTML to insert at the beginning of <head>.
var analyticsHTML template.HTML
2 changes: 1 addition & 1 deletion template/index.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en" ng-app="tour">

<head>
<meta charset="utf-8">
{{.AnalyticsHTML}} <meta charset="utf-8">
<title>A Tour of Go</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
Expand Down
7 changes: 4 additions & 3 deletions tour.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ func initTour(root, transport string) error {
buf := new(bytes.Buffer)

data := struct {
SocketAddr string
Transport template.JS
}{socketAddr(), template.JS(transport)}
AnalyticsHTML template.HTML
SocketAddr string
Transport template.JS
}{analyticsHTML, socketAddr(), template.JS(transport)}

if err := ui.Execute(buf, data); err != nil {
return fmt.Errorf("render UI: %v", err)
Expand Down

0 comments on commit 6bb846c

Please sign in to comment.