Redux Beacon
  • Introduction
  • Getting Started (Redux)
  • Getting Started (ngrx)
  • Examples & Recipes
  • Targets
    • GoogleAnalytics
    • GoogleAnalyticsGtag
    • GoogleTagManager
    • Segment
    • Amplitude
    • React Native: GoogleAnalytics
    • React Native: GoogleTagManager
    • React Native: Segment
  • API Reference
    • createMiddleware
    • createMetaReducer
    • EventDefinition
    • EventsMap
    • EventsMapper
  • Extensions
    • logger
    • OfflineWeb
    • OfflineReactNative
  • Utils
    • debounceEvent
    • ensure
    • combineEvents
  • FAQ
  • Migration Guide (v1 to v2)
  • Notes on Offline Events
Powered by GitBook
On this page
  • Setup
  • Usage
  • Event Definitions
  • pageView
  • event
  • alias
  • group
  • identify
  • reset
  1. Targets

Segment

PreviousGoogleTagManagerNextAmplitude

Last updated 7 years ago

Setup

  1. for Segment.io and create a Segment.io project for your web application.

  2. Add the to your site.

    During development and testing it is often helpful to use the debug version of analytics.js. Follow the instructions to enable it.

  3. Install the target:

     npm install --save @redux-beacon/segment

Usage

import Segment from '@redux-beacon/segment';

// Create or import an events map.
// See "getting started" pages for instructions.

const segment = Segment();

const segmentMiddleware = createMiddleware(eventsMap, segment);
const segmentMetaReducer = createMetaReducer(eventsMap, segment);

Event Definitions

pageView

Docs:

import { trackPageView } from '@redux-beacon/segment';

const pageView = trackPageView((action, prevState, nextState) => {
  return {
    category: /* (optional) */
    name: /* (optional) */
    properties: /* (optional) */
    options: /* (optional) */
  };
});

The last line of the tracking snippet analytics.page(); hits Segment.io with a page view that matches the first loaded route. If you're tracking page views using Redux Beacon, be sure to remove this line so the initial page load isn't recorded twice.

event

Docs:

import { trackEvent } from '@redux-beacon/segment';

const event = trackEvent((action, prevState, nextState) => {
  return {
    name: /* fill me in */,
    properties: /* (optional) */,
    options: /* (optional) */,
  };
});

alias

Docs:

import { setAlias } from '@redux-beacon/segment';

const alias = setAlias((action, prevState, nextState) => {
  return {
    userId: /* fill me in */,
    previousId: /* (optional) */,
    options: /* (optional) */,
  };
});

group

Docs:

import { setGroup } from '@redux-beacon/segment';

const group = setGroup((action, prevState, nextState) => {
  return {
    groupId: /* fill me in */,
    traits: /* (optional) */,
    options: /* (optional) */,
  };
});

identify

Docs:

import { identifyUser } from '@redux-beacon/segment';

const user = identifyUser((action, prevState, nextState) => {
  return {
    userId: /* (optional) */,
    traits: /* (optional) */,
    options: /* (optional) */,
  };
});

reset

Docs:

import { reset } from '@redux-beacon/segment';

const resetRequest = reset();

Don't see your event listed? Please submit a pull request to the with the missing event. Use the source of the existing event-helpers to guide your work. If you need any support feel free to make the pull request with all you're able to do. We can fill in the gaps from there.

Redux Beacon repository
https://segment.com/docs/sources/website/analytics.js/#page
https://segment.com/docs/sources/website/analytics.js/#track
https://segment.com/docs/sources/website/analytics.js/#alias
https://segment.com/docs/sources/website/analytics.js/#group
https://segment.com/docs/sources/website/analytics.js/#identify
https://segment.com/docs/sources/website/analytics.js/#reset-logout
Sign up
JavaScript Tracking Snippet
here
Setup
Usage
Event Definitions
pageView
event
alias
group
identify