diff --git a/lib/customEvents.js b/lib/customEvents.js index bee44f5b4..42afb119d 100644 --- a/lib/customEvents.js +++ b/lib/customEvents.js @@ -77,4 +77,8 @@ function enrich(beacon: CustomEventBeacon, opts: CustomEventOptions) { if (typeof opts['componentStack'] === 'string') { beacon['cs'] = opts['componentStack'].substring(0, 4096); } -} + + if (typeof opts['customMetric'] === 'number') { + beacon['cm'] = opts['customMetric']; + } +} diff --git a/lib/types.js b/lib/types.js index b8b0e569d..01fa7c2bf 100644 --- a/lib/types.js +++ b/lib/types.js @@ -241,7 +241,10 @@ export interface CustomEventBeacon extends Beacon { // error stack st: ?string, // component stack - cs: ?string + cs: ?string, + + //custom metric + cm: ?number } export interface CustomEventOptions { @@ -265,7 +268,10 @@ export interface CustomEventOptions { // to permit ['foo'] based access that doesn't break // when pushed through the Closure compiler - [key: string]: any + [key: string]: any, + + // Any custom metric that can be passed with custom events Example: 123.2342 + customMetric: ?number } export interface PageChangeBeacon extends Beacon { diff --git a/test/e2e/09_customEvents/customEvents.spec.js b/test/e2e/09_customEvents/customEvents.spec.js index ff80e1504..17cb3d354 100644 --- a/test/e2e/09_customEvents/customEvents.spec.js +++ b/test/e2e/09_customEvents/customEvents.spec.js @@ -35,6 +35,7 @@ describe('09_customEvents', () => { cexpect(beacon.m_kind).to.equal('experienced'); cexpect(beacon.m_state).to.equal('broken'); cexpect(beacon.bt).to.equal('ab87128a1ff99345'); + cexpect(beacon.cm).to.equal('123.2342'); }); }); }); @@ -83,4 +84,60 @@ describe('09_customEvents', () => { }); }); }); + + describe('simpleEventReportingWithoutCustomMetric', () => { + beforeEach(() => { + browser.get(getE2ETestBaseUrl('09_customEvents/simpleEventReportingWithoutCustomMetric')); + }); + + it('must report custom events', () => { + return retry(() => { + return getBeacons().then(beacons => { + const pageLoadBeacon = expectOneMatching(beacons, beacon => { + cexpect(beacon.ty).to.equal('pl'); + }); + + expectOneMatching(beacons, beacon => { + cexpect(beacon.ty).to.equal('cus'); + cexpect(beacon.ts).to.be.a('string'); + cexpect(beacon.n).to.equal('testWithEmptyCustomMetric'); + cexpect(beacon.e).to.match(/Testing 123/); + cexpect(beacon.pl).to.equal(pageLoadBeacon.t); + cexpect(beacon.bt).to.equal('ab87128a1ff99345'); + cexpect(beacon.cm).to.be.undefined; + }); + + expectOneMatching(beacons, beacon => { + cexpect(beacon.ty).to.equal('cus'); + cexpect(beacon.ts).to.be.a('string'); + cexpect(beacon.n).to.equal('testWithNoCustomMetric'); + cexpect(beacon.e).to.match(/something wrong/); + cexpect(beacon.pl).to.equal(pageLoadBeacon.t); + cexpect(beacon.bt).to.equal('ab87128a1ff99345'); + cexpect(beacon.cm).to.be.undefined; + }); + + expectOneMatching(beacons, beacon => { + cexpect(beacon.ty).to.equal('cus'); + cexpect(beacon.ts).to.be.a('string'); + cexpect(beacon.n).to.equal('testWithIncorrectCustomMetric'); + cexpect(beacon.e).to.match(/something wrong/); + cexpect(beacon.pl).to.equal(pageLoadBeacon.t); + cexpect(beacon.bt).to.equal('ab87128a1ff99345'); + cexpect(beacon.cm).to.be.undefined; + }); + + expectOneMatching(beacons, beacon => { + cexpect(beacon.ty).to.equal('cus'); + cexpect(beacon.ts).to.be.a('string'); + cexpect(beacon.n).to.equal('testWithExponentialCustomMetric(1e5)'); + cexpect(beacon.e).to.match(/something wrong/); + cexpect(beacon.pl).to.equal(pageLoadBeacon.t); + cexpect(beacon.bt).to.equal('ab87128a1ff99345'); + cexpect(beacon.cm).to.equal('100000'); + }); + }); + }); + }); + }); }); diff --git a/test/e2e/09_customEvents/simpleEventReporting.html b/test/e2e/09_customEvents/simpleEventReporting.html index 0aa90c2b6..f33478712 100644 --- a/test/e2e/09_customEvents/simpleEventReporting.html +++ b/test/e2e/09_customEvents/simpleEventReporting.html @@ -20,7 +20,8 @@ // one-off overwrite kind: 'experienced', state: 'broken' - } + }, + customMetric: 123.2342 }); diff --git a/test/e2e/09_customEvents/simpleEventReportingWithoutCustomMetric.html b/test/e2e/09_customEvents/simpleEventReportingWithoutCustomMetric.html new file mode 100644 index 000000000..c8eac9d77 --- /dev/null +++ b/test/e2e/09_customEvents/simpleEventReportingWithoutCustomMetric.html @@ -0,0 +1,69 @@ + + +
+ +