-
Notifications
You must be signed in to change notification settings - Fork 14
/
ga4.go
40 lines (31 loc) · 1.1 KB
/
ga4.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
37
38
39
40
package googleanalytics
import (
"context"
ga "google.golang.org/api/analyticsdata/v1beta"
"google.golang.org/api/option"
"github.com/coretrix/hitrix/service/component/config"
)
// GoogleAnalytics4 https://developers.google.com/analytics/devguides/reporting/data/v1
type GoogleAnalytics4 struct {
client *ga.Service
propertyID string
providerName Provider
}
func NewGA4(configFolder string, configService config.IConfig) (IProvider, error) {
configFilePath := configFolder + "/" + configService.MustString("google_analytics.config_file_name")
client, err := ga.NewService(context.Background(), option.WithCredentialsFile(configFilePath))
if err != nil {
return nil, err
}
return &GoogleAnalytics4{
client: client,
propertyID: configService.MustString("google_analytics.property_id"),
providerName: GA4,
}, nil
}
func (g *GoogleAnalytics4) GetName() Provider {
return g.providerName
}
func (g *GoogleAnalytics4) RunReport(runReportRequest *ga.RunReportRequest) (*ga.RunReportResponse, error) {
return g.client.Properties.RunReport("properties/"+g.propertyID, runReportRequest).Do()
}