Crosslytics
Tired of writing repetitive code to send the same analytics data to all your different tracking services? Or formatting the same data slightly differently for each service, like using eventAction
for Google Analytics but event_name
for Intercom?
Use Crosslytics for a unified event definition and analytics reporting API: Define events once and report them to all your analytics services with a single call. We've also abstracted the services themselves into a pluggable Tracker architecture so you can use only the services you need and quickly add support for new ones.
Why not use Segment? We didn't want to add another hosted service dependency, so we came up with a light-weight library to send telemetry directly. The meat of Crosslytics lies with its unified datamodels. The models are in fact based on the Segment spec, so usage semantics should actually be very similar.
Usage
Define events
Define some events by subclassing TrackedEvent
. Since the Crosslytics library is isomorphic, you only have to do this once. You can then share the same event definitions between your client and server code:
// events.ts;
Server-side
Express
Node.js withDo a one-time setup of trackers in your application code using Express middleware:
// server.ts;;;// Other trackers as desired, e.g.// import { IntercomTracker } from 'crosslytics-node-intercom-tracker'; ;app.use;
Now you can report events to all trackers using a single call:
// dashboard.controller.ts;app.route'panel'.post;
Client-side
React with Redux
We recommend adding analytics metadata to Redux Actions. For example, you could include an action.analytics
property when you want an action to be tracked. This way, you can setup Redux middleware to report analytics and greatly reduce the amount of tracking code you need to write.
First, do a one-time setup of trackers and create a middleware:
// middleware.ts;;;// Other trackers as desired, e.g.// import { IntercomTracker } from 'crosslytics-browser-intercom-tracker'; ; ;crosslytics.trackers.setgaTracker.id, gaTracker; // Add more trackers as desired// const intercomTracker = new IntercomTracker('token');// crosslytics.trackers.set('token', intercomTracker); // Create a middleware to use with your Redux store // Woohoo TypeScript type-safety
Then add the middleware to your Redux store (also one-time):
// store.ts;; ; // If you're using a router, you can also track page views; // your router of choice, e.g. 'react-router-redux'history.listencrosslytics.page;
Finally, you can now just add an action.analytics
property to your actions and the events will be tracked automatically by the middleware. An example async action creator:
// dashboards.actions.ts // See server example: this is the same event defintion across client and server; // Action for successful panel creation;
Trackers
Docs coming soon