A tool to use (and render) Segments open-source analytics library (analytics.js) WITHOUT using the paid Segment service (segment.com). To be used with your favorite analytics-tools like Google Analytics, Mixpanel, Hotjar, etc.
@Gatsby-users: Use the related gatsby-package.
cdnUrl
and services
).analytics.track()
Install via npm
npm install analytics-js-without-segment --save
In your client, add:
const { renderAnalytics, runAnalytics } = require('analytics-js-without-segment')
const options = {
cdnUrl: 'https://cdnjs.cloudflare.com/ajax/libs/analytics.js/2.9.1/analytics.min.js', // host yourself or use cdnjs (https://cdnjs.com/libraries/analytics.js)
services: {
// see integration https://github.com/segment-integrations/analytics.js-integration-google-analytics/blob/master/lib/index.js
'Google Analytics': {
trackingId: 'UA-XXX-1',
anonymizeIp: true,
},
// see integration https://github.com/segment-integrations/analytics.js-integration-mixpanel/blob/master/lib/index.js
'Mixpanel': {
token: 'XXX',
people: true,
trackAllPages: true,
},
// see integration https://github.com/segment-integrations/analytics.js-integration-fullstory/blob/master/lib/index.js
'FullStory': {
org: 'XXX',
debug: true,
},
// ... other service? See supported integrations (that can be loaded via analytics.js) at https://github.com/segment-integrations.
},
}
// OPTION 1)
// AUTOMATICALLY attach to window.analytics and make global `analytics.*`-object available
runAnalytics(options) // after running this, `analytics` is globally available
// OPTION 2)
// MANUALLY attach to window.analytics and make global `analytics.*`-object available
const snippet = renderAnalytics(options)
eval(snippet)
The concept of analytics.js is awesome. BUT Segments's free tier (max 1.000 monthly users) might not work for you, if you have a lot of non-paying visitors on your website.
So if you want an easy-to-configure analytics.js
-wrapper for your analytics (Google Analytics, Mixpanel, Hotjar, YouNameIt, ...), then this is your go-to! Basically ALL big analytics-integrations are supported.
This solution is open source, unlimited and free forever!
Background (state 2018-10-24): Segment.com has aggressive pay-or-leave policies, which they will apply after you hit the 1000 free monthly users limit. They will lock your account and stop processing your events after a deadline.
Advantages:
analytics.page()
or analytics.track()
)Disadvantages:
You should be able to use ALL services that segment itself supports and has integrations available. You'll have to dig around a bit in segment's code to find the options for each individual tool.
Check out the supported Integrations (that can be loaded via analytics.js) at https://github.com/segment-integrations.
This is project is based on https://gist.github.com/typpo/5e2e4403c60314e04e8b6b257555f6de and the related blogpost at http://www.ianww.com/blog/2017/08/06/analytics-js-standalone-library/.
CLI cheatsheat:
npm run build-watch; # auto-compile on file-change from /src to / via babel
MIT