Search code examples
google-analyticsredux-beacon

How to get multiple trackers to work using @redux-beacon/google-analytics?


I'm using redux-beacon and google-analytics in my project to track ecommerce events in two Google Analytics-accounts. As not all data is coming through in the reports I'm trying to debug where it goes wrong using the Google Analytics Debugger Chrome Extension. It seems that all calls throw a 'Set called on unknown field: "customTrackerId".' Has anybody come across this before?

import {
  trackEcommProduct,
  trackEcommAction,
  trackPageView,
  trackEvent
} from '@redux-beacon/google-analytics';

export const CLIENT_TAG = 'client';

const getLocation = () => window.location.href;
const getPage = () => getLocation().split('#')[1];

export const clientPageView = trackPageView((action, prevState, nextState) => ({
  location: getLocation(),
  page: getPage(),
  title: action.title
}), CLIENT_TAG);

Pasting the events on the console spit by the chrome extension:

VM20555 analytics_debug.js:15 Executing Google Analytics commands.
VM20555 analytics_debug.js:15 Running command: ga("client.set", "page", "/product/4")
VM20554 app.ba606e9ace53a50ecd21.js:93766 CC client.
VM20555 analytics_debug.js:15 Executing Google Analytics commands.
VM20555 analytics_debug.js:15 Running command: ga("client.send", {hitType: "pageview", customTrackerId: "client", page: "/product/4", title: undefined, location: "http://localhost:3333/#/product/4"})
VM20555 analytics_debug.js:15 Set called on unknown field: "customTrackerId".
VM20555 analytics_debug.js:15 
Sent beacon:
v=1&_v=j76d&a=291005201&t=pageview&_s=1&dl=http%3A%2F%2Flocalhost%3A3333%2F%23%2Fproduct%2F4&dp=%2Fproduct%2F4&ul=es-es&de=UTF-8&dt=Here's%20a%20title%20from%20setting%3A%20frontoffice_title&sd=24-bit&sr=1440x900&vp=830x766&je=0&_u=SCCACEIJB~&jid=&gjid=&cid=709854029.1557150989&tid=UA-62066942-1&_gid=86805739.1559994923&z=310945797

Solution

  • Thanks for pointing this out. This looks to be an issue on our end. The trackPageView event helper adds a customTrackerId property to the event to allow us make hits with a given tracker id (or set of tracker ids). There's no need for this property to exist outside redux-beacon so I've just parsed it out of any outgoing events. I've published a new version of the google-analytics target:

    npm install @redux-beacon/[email protected]
    

    Give it a go, and let me know if it fixes your issue!