-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
36 lines (31 loc) · 990 Bytes
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package ga4m
import (
"net/http"
"time"
)
// HTTPClient interface allows for mocking of http.Client in tests
type HTTPClient interface {
Do(req *http.Request) (*http.Response, error)
}
// AnalyticsClient is the client for sending events to Google Analytics
type AnalyticsClient struct {
MeasurementID string
APISecret string
Endpoint string
DebugEndpoint string
HTTPClient HTTPClient
}
// NewClient creates a new AnalyticsClient with the provided measurement ID and API secret
func NewClient(measurementID, apiSecret string) *AnalyticsClient {
return &AnalyticsClient{
MeasurementID: measurementID,
APISecret: apiSecret,
Endpoint: "https://www.google-analytics.com/mp/collect",
DebugEndpoint: "https://www.google-analytics.com/debug/mp/collect",
HTTPClient: &http.Client{Timeout: 5 * time.Second},
}
}
// SetHTTPClient allows setting a custom HTTP client
func (c *AnalyticsClient) SetHTTPClient(client HTTPClient) {
c.HTTPClient = client
}