Git Product home page Git Product logo

analytics.js's Introduction

โš ๏ธ Be sure to check out the next generation of analytics.js! https://github.com/segmentio/analytics-next ๐ŸŽ‰ If you have an existing JavaScript source with Segment, you can enable Analytics Next in the settings of the source.

Analytics.js

Analytics.js makes it easy to collect customer data and send it to many different tools using a single, unified API.

Analytics.js is open source and is one of the libraries that powers Segment, the managed, hassle-free way to collect customer data in the browser and beyond.

For our mobile and server-side data collection libraries, check out our catalog or our libraries page.

You can't fix what you can't measure

Analytics helps you measure your users, product, and business. It unlocks insights into your app's funnel, core business metrics, and whether you have product-market fit.

How to get started

  1. Collect analytics data from your app(s). Get started through Segment with our Analytics.js Quickstart.
    • The top 200 Segment companies collect data from 5+ source types (web, mobile, server, CRM, etc.).
  2. Send the data to analytics tools (for example, Google Analytics, Amplitude, Mixpanel).
    • Over 250+ Segment companies send data to eight categories of destinations such as analytics tools, warehouses, email marketing and remarketing systems, session recording, and more.
  3. Explore your data by creating metrics (for example, new signups, retention cohorts, and revenue generation).
    • The best Segment companies use retention cohorts to measure product market fit. Netflix has 70% paid retention after 12 months, 30% after 7 years.

Segment collects analytics data and allows you to send it to more than 250 apps (such as Google Analytics, Mixpanel, Optimizely, Facebook Ads, Slack, Sentry) just by flipping a switch. You only need one Segment code snippet, and you can turn integrations on and off at will, with no additional code. Sign up with Segment today.

Why?

  1. Power all your analytics apps with the same data. Instead of writing code to integrate all of your tools individually, send data to Segment, once.

  2. Install tracking for the last time. We're the last integration you'll ever need to write. You only need to instrument Segment once. Reduce all of your tracking code and advertising tags into a single set of API calls.

  3. Send data from anywhere. Send Segment data from any device, and we'll transform and send it on to any tool.

  4. Query your data in SQL. Slice, dice, and analyze your data in detail with Segment SQL. We'll transform and load your customer behavioral data directly from your apps into Amazon Redshift, Google BigQuery, or Postgres. Save weeks of engineering time by not having to invent your own data warehouse and ETL pipeline.

    For example, you can capture data on any app:

    analytics.track('Order Completed', { price: 99.84 })

    Then, query the resulting data in SQL:

    select * from app.order_completed
    order by price desc

๐Ÿš€ Startup Program

If you are part of a new startup (<$5M raised, <2 years since founding), we just launched a new startup program for you. You can get a Segment Team plan (up to $25,000 value in Segment credits) for free up to 2 years โ€” apply here!

Documentation

First, read the Analytics.js QuickStart, which contains installation instructions and a brief overview of what Analytics.js does and how it works.

For more detail on the Analytics.js API, check out the Analytics.js Library Reference.

Using this Repo

This repository houses a pre-built, open-source version of analytics.js. If you'd like to use Analytics.js outside of Segment but don't need to customize your build, pre-built unminified or minified versions of analytics.js found in the root of this repository. Once you've done that, you'll want to mimic the Segment snippet on your website by stubbing out its methods on the window and downloading your built version of the script asynchronously. For an example of doing that and initializing your integrations with options, see here.

If you're looking to produce a custom build of Analytics.js with just the plugins you need, see the wiki page for building a custom distribution.

Contributing to Analytics.js and its Ecosystem of Integration Plugins

The core logic of analytics.js is broken out into individual repositories:

  • To report an issue with analytics.js itself, head over to analytics.js-core, where the core analytics.js logic is maintained.
  • To report an issue with an integration plugin. head over to the analytics.js-integrations organization, where we keep each integration plugin in its own repository.
  • To build a custom integration plugin for analytics.js, check out the wiki. To distribute your plugin as a component of an integration in our catalog, check out our partner docs.

If you're not sure where to open an issue, feel free to open an issue against this repository or contact us and we'll help point you in the right direction.

License

Released under the MIT license.

analytics.js's People

Contributors

amillet89 avatar araddon avatar azcoov avatar bialecki avatar billyvg avatar buger avatar calvinfo avatar coryvirok avatar dangrossman avatar danieljackins avatar devangpaliwal avatar dkador avatar dominicbarnes avatar f2prateek avatar ianstormtaylor avatar jede avatar jessbrandi avatar koushan avatar lancejpollard avatar mchail avatar ndhoule avatar nscott avatar orta avatar philfreo avatar reinpk avatar robv avatar sanscontext avatar simontabor avatar sperand-io avatar yields avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

analytics.js's Issues

Feature request: When calling analytics.track() allow specifying which providers to use

Calling analytics.track() calls all the enabled providers. This is usually good, but in some cases, there are tracking request I'd like to forward to google and and not to mixpanel or vice a versa, so what I'd like is for analytics.track() to provide a way of (optionally) specifying which providers to use with this call and which not.
I'd imagine the API such as:

analytics.track(eventName, trackingData, opt_callback, opt_providers)

Where providers could be a blacklist or a whitelist.
For example:

{ga: true} // Use only GA
{ga: false} // Use all others except GA.

Support for Mixpanel's full API

Functions like registerOnce (which we use to track landing pages) are missing from the Segment.io API. This would be fine if we could get reliable access to the Mixpanel object. Using the loaded version of analytics.js there arn't any callbacks when a library is loaded, nor are any function calls buffered.

This is the only blocker to us using Segment.io right now.

Feature request: Allow calling _gat._getTrackerByName()._trackEvent

In some cases I'd like to call _gat._getTrackerByName()._trackEvent directly, rather than going through _gaq.push(['_trackEvent', ...])
_gaq is asynchronous, so when I want to send something right now I prefer calling _gat. For example when a user navigates away from my page, I want to make the best effort to sent some data to ga before the page is gone and from my testing it seems that gat gives us a better chance (although not guaranteed) to get the data across to google before the page is gone.

Does it make sense to add support for sync event like this?

add callbacks

they should have a short timeout so that the root page is never blocked by a provider not returning fast enough

Thoughts on GA custom variable (and w/ new Google analytics.js, custom dimensions/metrics)

I'm curious to see if anyone's thinking about or working on support for either classic ga.js custom variables or new-school Google analytics.js custom dimensions and metrics with analytics.js. So far I've thought about three ways of doing it:

  1. Hijack identify() -- GA doesn't accept personally identifiable data so we ignore the identifier and parse out specific properties (slot, category, value, and scope).. custom vars are used to segment users so I think there is some logic to this

  2. Hijack track() -- setting a custom variable doesn't match the semantics of track very well to me, so I like this less, but it's conceivable

  3. Either add a separate method for the provider or do it entirely out-of-band -- the dirty feeling I get when I think about this makes me sad and is what led me to options 1 and 2.

I must admit I haven't spent a lot of time on this, but I don't currently see an answer to it w/ analytics.js and I wanted to see if it seems appropriate and within the scope of the project, or if I should just pursue another course.

Docs

http://segmentio.github.com/analytics.js/ is still first in google for "analytics.js" -- I'm assuming it's out of date now, you should redirect it :)

would be nice if you hosted the new docs on github (are they?). for example, i see a mistake in the mixpanel page (since #60)

Allow Mixpanel name_tag customization

Personally I don't want the mixpanel name_tag to use the user_id, so it would be nice if there was a way to customize this. Possibly passing in a trait name into initialize to override the current behavior?

add an alias method

that combines Mixpanel's and KISSmetrics's. If you know of any other provider that supports aliasing (or merging) accounts feel free to comment here

add support for optimizely

a little trickier since they are sync. i think we'll require that their snippet is already on the page, but if it is well let you use our api to route to them

Support Google Analytics ecommerce events/transactions

As explained in chat yesterday we use Fastspring.com for our shop, the push this as an "e-commerce" transaction into GA when somebody bought. Can you do the same?

    <script type="text/javascript">
        var _gaq = _gaq || [];
        _gaq.push(['_setAccount', 'UA-20537420-1']);
        _gaq.push(['_setAllowLinker', true]);
_gaq.push(['_addIgnoredRef', 'veodin.com']);

        _gaq.push(['_trackPageview']);
            _gaq.push(['_addTrans', 
'VEO130303-8530-26143',
'KeyRocket Store',
'0.00',
'',
'0.00',
'Berlin',
'',
'DE'
]);
_gaq.push(['_addItem', 
'VEO130303-8530-26143',
'KeyRocket Premium - One-time Payment',
'KeyRocket Premium',
'',
'0.00',
'1'
]);

            _gaq.push(['_trackTrans']);

        (function() {
            var ga = document.createElement('script'); 
            ga.type = 'text/javascript'; 
            ga.async = true;
            ga.src = "https://ssl.google-analytics.com/ga.js";
            var s = document.getElementsByTagName('script')[0]; 
            s.parentNode.insertBefore(ga, s);
        })();
    </script>   

clarification: multiple calls to identify for same userId?

In the docs for identify I am unable to find any guidance for whether the method should be called once per userId (ever) or whether it is safe -- or even advisable -- to call it anytime a userId authenticates.

In a similar vein, if one calls identify multiple times for the same userId, but provides extra traits for the userId beyond those used on the first call, does that cause segment.io to view the userId as a new one?

each service should be a separate plugin

I doubt someone will need all services on the same app, users will surely need other providers that aren't supported.

I think a better approach would be to break each adapter into its own file and create a method like analytics.register(providerId, adapter).

by splitting into separate files you don't need to care about file size, user will load only what they need.

Getting `_kmq is null or not an object` error on IE 8

I'm getting a weird error when I attempt to use analytics.js with KISSmetrics on IE 8:

_kmq is null or not an object

Some specifics:

  • Error is being thrown when the kissmetrics js lib is loaded via _kms('//doug1izaerwt3.cloudfront.net/'+...);
  • Right before that, but after the statement window._kmq = _kmq;, logging _kmq returns an object with no keys.
  • Inside the dynamically loaded kissmetrics js lib, error is being thrown at: _kmq.push(["au"]). At that point, window._kmq is for some reason undefined.

Error on loading analytics.js asynchronously after page load

I'm seeing an error when trying to load analytics.js later on, after the page has loaded. I have a function, loadAnalyticsJs which is called later on in the page execution, since we only want to track a small subset of page views.

// Function to lazy-load analytics.js
var loadAnalyticsJs = function() {
  var analytics=analytics||[];analytics.load=function(e){var t=document.createElement("script");t.type="text/javascript",t.async=!0,t.src=("https:"===document.location.protocol?"https://":"http://")+"d2dq2ahtl5zl1z.cloudfront.net"+"/analytics.js/v1/"+e+"/analytics.min.js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(t,n);var r=function(e){return function(){analytics.push([e].concat(Array.prototype.slice.call(arguments,0)));};},s=["identify","track"];for(var i=0;i<s.length;i++)analytics[s[i]]=r(s[i]);},
  analytics.load("XXXXXXX");
};

// Example of usage that causes error
setTimeout(loadAnalyticsJs, 10000);

When this is used, I see this error in the console:

Uncaught TypeError: Cannot read property 'length' of undefined analytics.min.js:4

I haven't had the chance to look through the un-minified source for analytics.js yet, but I'm guessing this has something to do with inspecting the script tags on the page, and that analytics.js is assuming the presence of a script tag that loaded it?

Standardize providers identification keys.

Hi,

kudos for yuor great library.

I think that having standard name for provider's id key would simplify provider's abstraction.

Now we have:
for Google analytics -> trackingId
for Mixpanel -> token
for KISSmetrics -> apiKey
...

The standard way:
for Google analytics -> id
for Mixpanel -> id
for KISSmetrics -> id
...

Then every provider should change that key name accordingly to their apis.

Document date formats

For created and lastSeen, would be good to know if analytics.js is expecting a Date() object, a string in a certain format, or a unix timestamp

allow to disable pageview tracking for certain providers (google analytics)

We use a GA with a wordpress plugin and I want to keep it that way because they have more features.

I still like to use segment.io > Google Analytics for all the custom events we do via .track()

Therefore I need to disable that pageviews are sent to GA via segment.io

(Thinking about it this might leed to GA being loaded twice, any ideas? :-/)

Repeated paragraph in README

There's a track code sample right after the identify section.

The same code is repeated in the track section.

Using from Backbone.js

I'm having huge issues implementing analytics.js in a "smart" way using Backbone.

I have multiple main HTML layouts in my Rails application, and each of those layouts have a main Backbone view that has multiple nested Backbone view. Each of these apps needs to call the track function of analytics.js.

So I want to wrap my analytics object in a Backbone view that all these apps have access to. This view will also store information about the user, so each individual piece of code doesn't need to know these things.

However, I'm having huge problems with what I think is scoping issues. It looks like analytics.js must be initialized in the root document. If I initialize the code in a backbone view (changning a few things for scoping issues), I get this:

Uncaught TypeError: Cannot set property 'identify' of undefined
Uncaught TypeError: Cannot call method 'track' of undefined
Uncaught TypeError: Cannot read property 'length' of undefined 

Even if I instantiate the analytics object in root, and then pass a reference to a Backbone view, I'm getting errors when calling track:

Uncaught TypeError: Object #<g> has no method 'push'

Is there a way to make this library a little more suited for JS code that uses a JS framework to order things nicely? Does anyone have an example of how to do this?

expose providers

there should be a way to monkey-patch and do some sort of AOP over the providers (eg. replace the methods to do some logging instead of actually calling the provider during development).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.