Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

redux-beacon

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redux-beacon

Analytics integration for Redux and ngrx/store

  • 2.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
33K
increased by3.06%
Maintainers
1
Weekly downloads
 
Created
Source

Redux Beacon

Redux Beacon

Analytics integration for Redux and ngrx/store

Docs

Introduction

If you're using Redux or ngrx/store to manage your app's state, you can use Redux Beacon to tap into your dispatched actions and map them to events that are consumable by an analytics service (e.g. Google Analytics). With Redux Beacon your entire global state life-cycle becomes trackable.

Redux Beacon is Lightweight

npm bundle size (minified + gzip)

The core Redux Beacon module is tiny (~ 1KB), and each target, extension, and util, is either around the same size or smaller.

Redux Beacon is Framework Agnostic

Redux Beacon doesn't depend on any framework, you can use Redux Beacon with React, Angular, React Native, Vue or just plain JavaScript.

Redux Beacon Can Send Analytics Anywhere

With Redux Beacon you can send analytics events anywhere. We have prebuilt targets for the most popular analytics services, you can also build your own custom targets if you need to.

Redux Beacon Can Track Analytics Offline

Redux Beacon provides extensions for tracking analytics during intermittent outages in connectivity. These extensions save events in a persistent store when offline (e.g indexedDB). When back online, the extensions purge the store and pass the events off to a target. Read more about offline event collection in the docs.

Packages

VersionPackage
npmredux-beacon
Googlenpm@redux-beacon/google-analytics
Googlenpm@redux-beacon/google-analytics-gtag
Googlenpm@redux-beacon/google-tag-manager
Googlenpm@redux-beacon/react-native-google-analytics
Googlenpm@redux-beacon/react-native-google-tag-manager
Amplitudenpm@redux-beacon/amplitude
Segmentnpm@redux-beacon/segment
🔌npm@redux-beacon/logger
🔧npm@redux-beacon/combine-events
🔧npm@redux-beacon/ensure
🔌npm@redux-beacon/offline-web
🔌npm@redux-beacon/offline-react-native

API Overview

When using Redux Beacon the bulk of your work will be in an eventsMap which is an object that maps action types to analytics events. Here's what an eventsMap might look like:

const eventsMap = {

  // Track a page view on each 'ROUTE_CHANGED' action
  'ROUTE_CHANGED': trackPageView(action => ({
    page: action.payload.routerState.url,
  })),


  // Track an event on each 'VIDEO_SELECTED' action, use the state before
  // the action and the state after the action to hydrate the analytics event
  'VIDEO_SELECTED': trackEvent((action, prevState, nextState) => ({
    category: 'Videos',
    action: action.type,
    label: prevState.videos.currentCampaign,
    value: nextState.videos.numVideosSelected,
  }))


  // Track an event on _every_ action with the special '*' key
  '*': trackEvent(action => ({
    category: 'redux',
    action: action.type,
  })),


  // Track multiple events on each 'VIDEO_PLAYED' action with the
  // combineEvents util
  'VIDEO_PLAYED': combineEvents(
    trackTiming(action => ({
      category: 'Videos',
      action: 'load',
      value: action.payload.loadTime,
    }))
    trackEvent(() => ({
      category: 'Videos',
      action: 'play'
    })),
  ),


  // Track an event on each 'VIDEO_SEARCHED' action, but throttle it with
  // the debounceEvent util so it doesn't fire as often
  'VIDEO_SEARCHED': debounceEvent(300,
     trackEvent(action => ({
       category: 'Videos',
       action: 'search',
       label: action.payload.searchTerm,
     }))
   ),

};

The trackPageView, trackEvent, and trackTiming functions used above are called eventDefinitions and are what you use to create events that are consumable by an analytics service (a.k.a "target"). Each target will have its own set of eventDefinitions that you can use and customize. In a nutshell, each time you want to track something:

  1. Find the event definition for the thing you want to track.
  2. Match the event definition to an action then fill in the event definition.

If the eventsMap object doesn't meet your needs you can also use an eventsMapper function to map action types to event definitions:

const pageView = trackPageView(action => ({
  page: action.payload.routerState.url,
}));

const videoLoadTime = trackTiming(action => ({
   category: 'Videos',
   action: 'load',
   value: action.payload.loadTime,
}));

const videoPlayed = trackEvent(() => ({
  category: 'Videos',
  action: 'play'
}));

const eventsMapper = (action) => {
  switch(action.type) {
    case 'ROUTE_CHANGED':
      return pageView;
    case 'VIDEO_PLAYED':
      return [videoLoadTime, videoPlayed]
    default:
      return [];
  }
}

Examples & Recipes

Keywords

FAQs

Package last updated on 01 Apr 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc