@dosomething/analytics

A simple wrapper for Google Analytics and Optimizely.

Stats

stars 🌟issues ⚠️updated 🛠created 🐣size 🏋️‍♀️
@dosomething/analytics
Minified + gzip package size for @dosomething/analytics in KB

Readme

Analytics NPM

This is a simple helper for triggering analytics events in the browser. It supports sending events to Google Analytics and Optimizely (via their official snippets). It's super tiny (510 bytes gzipped)!

Installation

You can get your own copy of Analytics using npm:

npm install @dosomething/analytics

Include the bundled dist/Analytics.js in your page, or require it using a module bundler.

Usage

You can manually send an event with Analytics.analyze('category', 'action', 'label').

You can also trigger events by setting data attributes on clickable items, or by using the global analyze() helper method in an inline script anytime after running Analytics.init():

   <script src="dist/analytics.js"></script>
   <script type="text/javascript">
     Analytics.init();
   </script>


   <!-- Any click on this link will trigger a 'Link:Clicked:Click Me' event. -->
   <a href="#" data-track-category="Link" data-track-action="Clicked" data-track-label="Click Me">Click Me!</a>

   <!-- Any page load will trigger a 'Page:Loaded:Demo' event. -->
   <script type="text/javascript">
     analyze('Page:Loaded:Demo');
   </script>

License

©2016 DoSomething.org. Analytics is free software, and may be redistributed under the terms specified in the LICENSE file. The name and logo for DoSomething.org are trademarks of Do Something, Inc and may not be used without permission.

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.