Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Analytics integration for Redux and ngrx/store

License

NotificationsYou must be signed in to change notification settings

rangle/redux-beacon

Redux Beacon

Redux Beacon

Analytics integration for Redux and ngrx/store

Introduction

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

Redux Beacon Diagram

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

  • You can use Redux Beacon with any framework. Redux Beacon doesn't depend on anyframework, you can use Redux Beacon with React, Angular, React Native, Vue orjust plain JavaScript.

  • You can send analytics anywhere. We have prebuilt targets for the mostpopular analytics services, you can also build your own custom targets if youneed to.

  • You can track analytics offline. Redux Beacon providesextensions for tracking analytics during intermittent outages inconnectivity. These extensions save events in a persistent store when offline(e.g indexedDB). When back online, the extensions purge the store and passthe events off to a target. Read more about offline event collection in thedocs.

Supported Targets

VersionPackage
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
Segmentnpm@redux-beacon/react-native-segment

Third-Party Targets

VersionPackage
Matomonpmredux-beacon-matomo-tag-manager
Appsflyernpmredux-beacon-react-native-appsflyer

Other Targets

If you don't see your analytics target listed it might be worth a shot doing a quick search on npmjs.org. If all else fails you can alwaysbuild and provide your own custom Targets!

Integrations

IntegrationIntegrates withDescription
redux-dynamic-modules-beaconredux-dynamic-modulesRedux Dynamic Modules is a library that allows to modularize redux code. With help of this extension events do not have to be defined in one central location but can be defined for each module individually.

Usage

  • Step 1. Pick out a target(see above)

  • Step 2. Pick out some events you want to track from your target's Event Definitions section

  • Step 3. Match the events to action types(see below)

Examples

Track a page view on eachROUTE_CHANGED action

consteventsMap={'ROUTE_CHANGED':trackPageView(action=>({page:action.payload.routerState.url,})),}

Track an event on eachVIDEO_SELECTED action, use the state before the actionand the state after the action to hydrate the analytics event

consteventsMap={'VIDEO_SELECTED':trackEvent((action,prevState,nextState)=>({category:'Videos',action:action.type,label:prevState.videos.currentCampaign,value:nextState.videos.numVideosSelected,}))}

Track an event onevery action using the special '*' key

consteventsMap={'*':trackEvent(action=>({category:'redux',action:action.type,})),}

Track multiple events on eachVIDEO_PLAYED action using thecombineEvents util

consteventsMap={'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

consteventsMap={'VIDEO_SEARCHED':debounceEvent(300,trackEvent(action=>({category:'Videos',action:'search',label:action.payload.searchTerm,}))),}

ThetrackPageView,trackEvent, andtrackTiming functions used above arecalledeventDefinitions and are what you use to create events that areconsumable by an analytics service (a.k.a "target"). Each target will have itsown set ofeventDefinitions that you can use and customize.

Don't like the idea of using an object to map actions?

You can use a function...

constpageView=trackPageView(action=>({page:action.payload.routerState.url,}));constvideoLoadTime=trackTiming(action=>({category:'Videos',action:'load',value:action.payload.loadTime,}));constvideoPlayed=trackEvent(()=>({category:'Videos',action:'play'}));consteventsMapper=(action)=>{switch(action.type){case'ROUTE_CHANGED':returnpageView;case'VIDEO_PLAYED':return[videoLoadTime,videoPlayed]default:return[];}}

More Examples & Recipes

Extensions & Plugins

VersionPackage
🔌npm@redux-beacon/logger
🔧npm@redux-beacon/combine-events
🔧npm@redux-beacon/ensure
🔧npm@redux-beacon/debounce-event
🔌npm@redux-beacon/offline-web
🔌npm@redux-beacon/offline-react-native

[8]ページ先頭

©2009-2025 Movatter.jp