From 63c5b0575d79c66bfcdd21a563f60b18cca8f0d4 Mon Sep 17 00:00:00 2001 From: James Nesbitt Date: Tue, 3 Dec 2024 14:02:38 +0200 Subject: [PATCH] PRODENG-2805 drop segment tokens - token removed from code, can be injected at compile time - if token is empty, disable analytics - no need for dev/prod token separation, if it is getting injected Signed-off-by: James Nesbitt --- pkg/analytics/analytics.go | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/pkg/analytics/analytics.go b/pkg/analytics/analytics.go index 65503d09..09172759 100644 --- a/pkg/analytics/analytics.go +++ b/pkg/analytics/analytics.go @@ -13,11 +13,9 @@ import ( analytics "gopkg.in/segmentio/analytics-go.v3" ) -const ( - // ProdSegmentToken is the API token we use for Segment in production. - ProdSegmentToken = "FlDwKhRvN6ts7GMZEgoCEghffy9HXu8Z" //nolint:gosec // intentionally public - // DevSegmentToken is the API token we use for Segment in development. - DevSegmentToken = "DLJn53HXEhUHZ4fPO45MMUhvbHRcfkLE" //nolint:gosec // intentionally public +var ( + // SegmentToken is the API token we use for Segment. Set at compile time + SegmentToken = "" ) // Analytics is the interface used for our analytics client. @@ -36,11 +34,12 @@ type Client struct { var defaultClient Client func init() { - segmentToken := DevSegmentToken - if version.IsProduction() { - segmentToken = ProdSegmentToken + if SegmentToken == "" { + defaultClient = Client{IsEnabled: false} + return } - ac, err := NewSegmentClient(segmentToken) + + ac, err := NewSegmentClient(SegmentToken) if err != nil { log.Warnf("failed to initialize analytics: %v", err) return @@ -68,7 +67,6 @@ func NewSegmentClient(segmentToken string) (Analytics, error) { //nolint:ireturn // is enabled. func (c *Client) TrackEvent(event string, properties analytics.Properties) error { if !c.IsEnabled { - log.Debugf("analytics disabled, not tracking event '%s'", event) return nil } @@ -95,7 +93,6 @@ func (c *Client) TrackEvent(event string, properties analytics.Properties) error // is enabled. func (c *Client) IdentifyUser(userConfig *user.Config) error { if !c.IsEnabled { - log.Debug("analytics disabled, not identifying user") return nil } msg := analytics.Identify{