internal/frontend: add attribution params to CodeWiki link
Change-Id: I5585ed00e003063f6567b8ba2eacbe23ea9dc98c
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/731820
Auto-Submit: Ethan Lee <ethanalee@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
kokoro-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
diff --git a/internal/frontend/links.go b/internal/frontend/links.go
index b435ff9..3e8a4de 100644
--- a/internal/frontend/links.go
+++ b/internal/frontend/links.go
@@ -24,7 +24,8 @@
// depsDevTimeout is the time budget for making requests to deps.dev.
depsDevTimeout = 250 * time.Millisecond
- codeWikiPrefix = "/codewiki?url="
+ codeWikiPrefix = "/codewiki?url="
+ attributionParams = "?utm_source=first_party_link&utm_medium=go_pkg_web&utm_campaign="
)
var (
@@ -141,9 +142,9 @@
if resp.StatusCode != http.StatusOK {
return "", errors.New(resp.Status)
}
- res := codeWikiURLBase + path
+ res := codeWikiURLBase + path + attributionParams + path
if recordClick {
- res = codeWikiPrefix + res
+ res = codeWikiPrefix + url.QueryEscape(res)
}
return res, nil
}
diff --git a/internal/frontend/links_test.go b/internal/frontend/links_test.go
index e2e8300..1b93af2 100644
--- a/internal/frontend/links_test.go
+++ b/internal/frontend/links_test.go
@@ -6,6 +6,7 @@
import (
"context"
+ "fmt"
"io"
"log"
"net/http"
@@ -16,6 +17,10 @@
"golang.org/x/pkgsite/internal"
)
+func expectedCodeWikiURL(baseURL, path string) string {
+ return fmt.Sprintf("%s/%s?utm_source=first_party_link&utm_medium=go_pkg_web&utm_campaign=%s", baseURL, path, path)
+}
+
func TestCodeWikiURLGenerator(t *testing.T) {
// The log package is periodically used to log warnings on a
// separate goroutine, which can pollute test output.
@@ -50,12 +55,12 @@
{
name: "github repo",
modulePath: "github.com/owner/repo",
- want: server.URL + "/github.com/owner/repo",
+ want: expectedCodeWikiURL(server.URL, "github.com/owner/repo"),
},
{
name: "github repo subpackage",
modulePath: "github.com/owner/repo",
- want: server.URL + "/github.com/owner/repo",
+ want: expectedCodeWikiURL(server.URL, "github.com/owner/repo"),
},
{
name: "github repo not found",
@@ -70,7 +75,7 @@
{
name: "golang.org/x/ repo",
modulePath: "golang.org/x/glog",
- want: server.URL + "/github.com/golang/glog",
+ want: expectedCodeWikiURL(server.URL, "github.com/golang/glog"),
},
}
for _, tc := range testCases {