Skip to content

Commit

Permalink
Add ga dimension for config cookie (#515)
Browse files Browse the repository at this point in the history
* Add ga dimension for config cookie
* Update cookiesToDimensions to an array
* Move when cookie dimensions are set

Signed-off-by: Everett Ross <reverett@uber.com>
  • Loading branch information
everett980 committed Feb 13, 2020
1 parent 8cb13c4 commit fe083aa
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/jaeger-ui/src/types/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ export type Config = {
scripts?: TScript[];
topTagPrefixes?: string[];
tracking?: {
cookieToDimension?: {
cookie: string;
dimension: string;
}[];
gaID: string | TNil;
trackErrors: boolean | TNil;
};
Expand Down
2 changes: 1 addition & 1 deletion packages/jaeger-ui/src/utils/tracking/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import ReactGA from 'react-ga';
import * as tracking from './index';

let longStr = '---';
function getStr(len: number) {
function getStr(len) {
while (longStr.length < len) {
longStr += longStr.slice(0, len - longStr.length);
}
Expand Down
9 changes: 9 additions & 0 deletions packages/jaeger-ui/src/utils/tracking/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,15 @@ if (isGaEnabled) {
appName: 'Jaeger UI',
appVersion: versionLong,
});
const cookiesToDimensions = _get(config, 'tracking.cookiesToDimensions');
if (cookiesToDimensions) {
cookiesToDimensions.forEach(({ cookie, dimension }: { cookie: string; dimension: string }) => {
const match = ` ${document.cookie}`.match(new RegExp(`[; ]${cookie}=([^\\s;]*)`));
if (match) ReactGA.set({ [dimension]: match[1] });
// eslint-disable-next-line no-console
else console.warn(`${cookie} not present in cookies, could not set dimension: ${dimension}`);
});
}
if (isErrorsEnabled) {
const ravenConfig: RavenOptions = {
autoBreadcrumbs: {
Expand Down

0 comments on commit fe083aa

Please sign in to comment.