Unverified Commit 1eb2d664 authored by Imran Salam's avatar Imran Salam Committed by GitHub
Browse files

use factory function to generate analytics objects in Redux actions

parent 26c1f668
Pipeline #15325 failed with stage
in 2 minutes and 56 seconds
export enum AnalyticsCategory {
GLOBAL = 'Global'
}
export type AnalyticsOptions = {
action?: string;
label: string;
nonInteraction?: boolean;
value?: number;
};
export type AnalyticsType = {
ga: {
category: AnalyticsCategory;
} & AnalyticsOptions;
};
export const buildAnalyticsObject = (category: AnalyticsCategory) => (
data: AnalyticsOptions | string
): AnalyticsType => {
data = typeof data === 'string' ? { label: data } : data;
return {
ga: {
category,
...data
}
};
};
export const getGlobalAnalyticsObject = buildAnalyticsObject(
AnalyticsCategory.GLOBAL
);
import { createAction } from 'typesafe-actions';
import { BreakpointWidth } from './globalConfig';
import { getGlobalAnalyticsObject } from './analyticsHelper';
export const updateBreakpointWidth = createAction(
'browser/update-breakpoint-width',
(resolve) => {
return (breakpointWidth: BreakpointWidth) =>
resolve(breakpointWidth, {
ga: {
category: 'Browser',
label: 'Default Action'
}
});
resolve(
breakpointWidth,
getGlobalAnalyticsObject({ label: 'Default Action' })
);
}
);
import ReactGA from 'react-ga';
import { AnalyticsType } from 'src/analyticsHelper';
const googleTrackingID = process.env.GOOGLE_ANALYTICS_KEY
? process.env.GOOGLE_ANALYTICS_KEY
......@@ -19,12 +20,15 @@ class AnalyticsTracking {
// Track an event
public trackEvent(action: any) {
const { ga } = action.meta as AnalyticsType;
this.reactGA.event({
action: action.meta.ga.action ? action.meta.ga.action : action.type,
category: action.meta.ga.category,
label: action.meta.ga.label,
value: action.meta.ga.value,
nonInteraction: action.meta.ga.nonInteraction
action: ga.action ? ga.action : action.type,
category: ga.category,
label: ga.label,
nonInteraction: ga.nonInteraction,
transport: 'xhr',
value: ga.value
});
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment