eventLogging: Discard events with duplicate tokens

I6a38a261 made the eventLogging change listener count and discard
duplicate events and count duplicate tokens.

While we isolate the issue(s) that lead to duplication (reuse, likely)
of tokens, make the eventLogging change listener discard events with
duplicate tokens as well.

Bug: T161769
Bug: T163198
Change-Id: I0dbb16c37814d39d7aec35c8fb7cc7309704c550
This commit is contained in:
Sam Smith 2017-05-10 11:12:26 +01:00
parent d6424cb59d
commit c44fddf8cd
4 changed files with 17 additions and 5 deletions

Binary file not shown.

Binary file not shown.

View file

@ -57,7 +57,8 @@ module.exports = function ( boundActions, schema, track ) {
var eventLogging = state.eventLogging,
event = eventLogging.event,
token,
key;
hash,
shouldLog = true;
if ( !event ) {
return;
@ -67,6 +68,8 @@ module.exports = function ( boundActions, schema, track ) {
if ( tokenToSeenMap[ token ] === true ) {
track( 'counter.PagePreviews.EventLogging.DuplicateToken', 1 );
shouldLog = false;
}
tokenToSeenMap[ token ] = true;
@ -78,14 +81,18 @@ module.exports = function ( boundActions, schema, track ) {
// ...
//
// It's also remarkably easy to implement!!1
key = fnv1a32( JSON.stringify( event ) ).toString( 16 );
hash = fnv1a32( JSON.stringify( event ) ).toString( 16 );
// Has the event been seen before?
if ( hashToSeenMap[ key ] === true ) {
if ( hashToSeenMap[ hash ] === true ) {
track( 'counter.PagePreviews.EventLogging.DuplicateEvent', 1 );
} else {
hashToSeenMap[ key ] = true;
shouldLog = false;
}
hashToSeenMap[ hash ] = true;
if ( shouldLog ) {
schema.log( $.extend( true, {}, eventLogging.baseData, event ) );
}

View file

@ -167,4 +167,9 @@ QUnit.test( 'it should handle duplicate tokens', function ( assert ) {
],
'It should increment the duplicate token counter.'
);
assert.ok(
this.schema.log.calledOnce,
'It shouldn\'t log the event with the duplicate token.'
);
} );