Skip to content

Commit bb06110

Browse files
committed
Make URL struct member
1 parent 7c46686 commit bb06110

1 file changed

Lines changed: 28 additions & 21 deletions

File tree

  • internal/analytics/client/sync/reporters

internal/analytics/client/sync/reporters/pixel.go

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@ import (
1515
)
1616

1717
type PixelReporter struct {
18-
cfg *config.Instance
18+
url string
1919
}
2020

2121
func NewPixelReporter(cfg *config.Instance) *PixelReporter {
22-
reporter := &PixelReporter{cfg: cfg}
22+
reporter := &PixelReporter{
23+
url: sourcePixelURL(cfg),
24+
}
25+
2326
configMediator.AddListener(constants.AnalyticsPixelOverrideConfig, func() {
24-
reporter.cfg = cfg
27+
reporter.url = sourcePixelURL(cfg)
2528
})
2629
return reporter
2730
}
@@ -31,25 +34,9 @@ func (r *PixelReporter) ID() string {
3134
}
3235

3336
func (r *PixelReporter) Event(category, action, source, label string, d *dimensions.Values) error {
34-
var (
35-
pixelUrl string
36-
37-
envUrl = os.Getenv(constants.AnalyticsPixelOverrideEnv)
38-
cfgUrl = r.cfg.GetString(constants.AnalyticsPixelOverrideConfig)
39-
)
40-
41-
switch {
42-
case envUrl != "":
43-
pixelUrl = envUrl
44-
case cfgUrl != "":
45-
pixelUrl = cfgUrl
46-
default:
47-
pixelUrl = constants.DefaultAnalyticsPixel
48-
}
49-
50-
pixelURL, err := url.Parse(pixelUrl)
37+
pixelURL, err := url.Parse(r.url)
5138
if err != nil {
52-
return errs.Wrap(err, "Invalid pixel URL: %s", pixelUrl)
39+
return errs.Wrap(err, "Invalid pixel URL: %s", r.url)
5340
}
5441

5542
query := &url.Values{}
@@ -72,3 +59,23 @@ func (r *PixelReporter) Event(category, action, source, label string, d *dimensi
7259

7360
return nil
7461
}
62+
63+
func sourcePixelURL(cfg *config.Instance) string {
64+
var (
65+
pixelUrl string
66+
67+
envUrl = os.Getenv(constants.AnalyticsPixelOverrideEnv)
68+
cfgUrl = cfg.GetString(constants.AnalyticsPixelOverrideConfig)
69+
)
70+
71+
switch {
72+
case envUrl != "":
73+
pixelUrl = envUrl
74+
case cfgUrl != "":
75+
pixelUrl = cfgUrl
76+
default:
77+
pixelUrl = constants.DefaultAnalyticsPixel
78+
}
79+
80+
return pixelUrl
81+
}

0 commit comments

Comments
 (0)