Segment
A single library to include that then loads other analytics tools with easy/no code switching adding new tools
Best naming convention is OBJECT ACTION like "Event Created" and only track the flows you want not everything
Server vs Client Tracking
All libs just wrap the HTTP API
Client:
Needed for some tools(no server-side full-story)
Richer User Data(cookies, IP, user agent, referrer, UTMs, mobile device info)
Automatically assigns userId and stores in local storage
Server:
More accurate as can't be blocked by adblockers/etc
No automatic userID, must be explicitly set
Client Usage
Every event automatically grabs page info and user agent
/* global analytics */ //eslint fix
analytics.identify([userId], [traits], [options], [callback]);
analytics.identify(id, {
email: email,
status: source,
});
analytics.identify(id,{
name: user.name,
email: user.email,
},
{
integrations: {
All: true,
Mailchimp: false,
},
}
);
analytics.group(user.organization_id);
analytics.track(event, [properties], [options], [callback]);
analytics.track("Demo Recorded", {video_id});
Don't bother calling identify for anonymous client users, let Segment do its random id thing stored in local storage
npm i -D @types/segment-analytics
Server Usage
Elixir/Phoenix
mix.ex
{:segment, "~> 0.2.3"}
config.exs
config :segment,
write_key: "2iFFnRsCfi" #Segment API KEY
application.ex in the supervisor list
{Segment, Application.get_env(:segment, :write_key)}
Usage
Segment.Analytics.track(user_id, event, %{property1: "", property2: ""})
Segment.Analytics.identify(user_id, %{trait1: "", trait2: ""})
Node
const Analytics = require("analytics-node");
const analytics = new Analytics(conf.get("SEGMENT_KEY"));
analytics.track({userId: id, event: "Demo Recorded"})
analytics.identify({userId: id, traits: {email, username}})
Last updated