The analytics package is entirely dependant over segment, to use it you should add
a config key SEGMENT_CLIENT_KEY on docker/.env file.
To find the segment client key check this link.
This package is divided in four files:
The segment.go file exports a function to initialize the analytics client, and two superset of the original segment client functions Track and Identify. This functions will handle cases when the segment client is not initialized and will return an error if the client failed enqueueing a certain track/identify.
tracks.go will export an interface SegmentTrack that all the tracks should follow, this helps when trying to standardize the analytics package. The idea behind this is to always use a constructor for the track that we're trying to use instead of having different implementations all over the app.
Enum of events that can be used on tracks, those will be implemented on the tracks.go so they shouldn't appear in any other part of the application.
Similar as the tracks.go, although this is more specialized as it should only be used on user register/login/update parts of the application.
The current implementation only uses Tracks and Identifiers specs from the segment package, in order to add a new spec you should follow this steps:
internal/analytics/segment.go file, it should always receive an interface that will get the necessary data for the segment spec function that you want to add.internal/analytics folder with the name on plural of the spec you want to add.internal/analytics/tracks.go file.In order to add new metrics to the current implementation the process should be simple:
internal/analytics folder that you want to useFor any doubts about this document or how to improve the analytics you can reach us on discord!