aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEthan Lee <ethanalee@google.com>2025-12-22 04:13:00 +0000
committerGopher Robot <gobot@golang.org>2026-01-01 07:32:55 -0800
commit3a74f05acd7522e74e16a35bdf80301dae44cfc9 (patch)
tree964145499946e89c46c7d6b10144a74bab6ac0e7
parent5a4d5c58bc73e708a7a867b717b4757e67e6eec9 (diff)
downloadgo-x-pkgsite-3a74f05acd7522e74e16a35bdf80301dae44cfc9.tar.xz
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>
-rw-r--r--internal/frontend/links.go7
-rw-r--r--internal/frontend/links_test.go11
2 files changed, 12 insertions, 6 deletions
diff --git a/internal/frontend/links.go b/internal/frontend/links.go
index b435ff9b..3e8a4de4 100644
--- a/internal/frontend/links.go
+++ b/internal/frontend/links.go
@@ -24,7 +24,8 @@ const (
// 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 @@ func fetchCodeWikiURL(ctx context.Context, client *http.Client, path string, rec
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 e2e83009..1b93af24 100644
--- a/internal/frontend/links_test.go
+++ b/internal/frontend/links_test.go
@@ -6,6 +6,7 @@ package frontend
import (
"context"
+ "fmt"
"io"
"log"
"net/http"
@@ -16,6 +17,10 @@ import (
"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 @@ func TestCodeWikiURLGenerator(t *testing.T) {
{
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 @@ func TestCodeWikiURLGenerator(t *testing.T) {
{
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 {