Skip to content

Commit

Permalink
PRODENG-2805 drop segment tokens
Browse files Browse the repository at this point in the history
- 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 <[email protected]>
  • Loading branch information
james-nesbitt committed Dec 3, 2024
1 parent 5da259b commit 6071cfb
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions pkg/analytics/analytics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (

Check failure on line 16 in pkg/analytics/analytics.go

View workflow job for this annotation

GitHub Actions / Lint

File is not `gofumpt`-ed (gofumpt)
// SegmentToken is the API token we use for Segment. Set at compile time

Check failure on line 17 in pkg/analytics/analytics.go

View workflow job for this annotation

GitHub Actions / Lint

Comment should end in a period (godot)
SegmentToken = ""
)

// Analytics is the interface used for our analytics client.
Expand All @@ -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
Expand Down Expand Up @@ -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
}

Expand All @@ -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{
Expand Down

0 comments on commit 6071cfb

Please sign in to comment.