-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c1221f8
commit 202a816
Showing
2 changed files
with
83 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package v2 | ||
|
||
import ( | ||
"net/http" | ||
"net/url" | ||
"strings" | ||
) | ||
|
||
func MiddlewareRichsstsse(next ClientHandler) ClientHandler { | ||
v := "" | ||
return func(r *http.Request, event *Event) error { | ||
event.Richsstsse = &v | ||
return nil | ||
} | ||
} | ||
|
||
func MiddlewareTrackingID(v string) ClientMiddleware { | ||
return func(next ClientHandler) ClientHandler { | ||
return func(r *http.Request, event *Event) error { | ||
event.TrackingID = &v | ||
return nil | ||
} | ||
} | ||
} | ||
|
||
func MiddlewarProtocolVersion(v string) ClientMiddleware { | ||
return func(next ClientHandler) ClientHandler { | ||
return func(r *http.Request, event *Event) error { | ||
event.ProtocolVersion = &v | ||
return nil | ||
} | ||
} | ||
} | ||
|
||
func MiddlewarIgnoreReferrer(v string) ClientMiddleware { | ||
return func(next ClientHandler) ClientHandler { | ||
return func(r *http.Request, event *Event) error { | ||
event.IgnoreReferrer = &v | ||
return nil | ||
} | ||
} | ||
} | ||
|
||
func MiddlewarDebug(next ClientHandler) ClientHandler { | ||
v := "1" | ||
return func(r *http.Request, event *Event) error { | ||
if value, _ := r.Cookie("gtm_debug"); value != nil { | ||
event.IsDebug = &v | ||
} | ||
return nil | ||
} | ||
} | ||
|
||
func MiddlewarClientID(next ClientHandler) ClientHandler { | ||
return func(r *http.Request, event *Event) error { | ||
if value, _ := r.Cookie("_ga"); value != nil { | ||
clientID := strings.TrimPrefix(value.Value, "GA1.1.") | ||
event.ClientID = &clientID | ||
} | ||
return nil | ||
} | ||
} | ||
|
||
func MiddlewarDocument(next ClientHandler) ClientHandler { | ||
return func(r *http.Request, event *Event) error { | ||
if referrer, err := url.Parse(r.Referer()); err != nil { | ||
return err | ||
} else { | ||
event.DocumentLocation = &referrer.Path | ||
event.DocumentHostname = &referrer.Host | ||
} | ||
return nil | ||
} | ||
} |