Skip to content

Commit 5bd2332

Browse files
authored
feat(analytics): upstream server headers for setting document title (#37)
1 parent ac035c3 commit 5bd2332

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

analytics/tracker.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ import (
1818
"time"
1919
)
2020

21+
// HeaderTitle is an HTTP header that can be returned by an upstream server to
22+
// manually set the "Document Title" value.
23+
const HeaderTitle = "X-Gap-Title"
24+
2125
// HeaderUTMCampaign is an HTTP header that can be returned by an upstream
2226
// server to manually set the "Campaign Name" value.
2327
const HeaderUTMCampaign = "X-Gap-Utm-Campaign"
@@ -221,7 +225,9 @@ func (t *Tracker) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
221225

222226
// Set the "Document Title" value.
223227
// See: https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#dt
224-
if value, _ := getTitle(recorder); value != "" {
228+
if value := recorder.Header().Get(HeaderTitle); value != "" {
229+
params.Set("dt", value)
230+
} else if value, _ := getTitle(recorder); value != "" {
225231
params.Set("dt", value)
226232
}
227233

0 commit comments

Comments
 (0)