Merge pull request #40 from mozilla/issue-6757-client-id-as-entrypoint r=@philbooth

feat(metrics): Use the service name or client_id as the entrypoint if none given.
This commit is contained in:
Shane Tomlinson 2019-01-18 10:29:16 +00:00 коммит произвёл GitHub
Родитель 794070c97d 6f2792b2c8
Коммит 98ffc5a933
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 44 добавлений и 4 удалений

Просмотреть файл

@ -180,7 +180,7 @@ module.exports = {
}
}
return pruneUnsetValues({
const properties = pruneUnsetValues({
op: 'amplitudeEvent',
event_type: `${eventGroup} - ${eventType}`,
time: event.time,
@ -197,6 +197,21 @@ module.exports = {
event_properties: mapEventProperties(eventType, eventGroup, eventCategory, eventTarget, data),
user_properties: mapUserProperties(eventGroup, eventCategory, data)
});
if (! properties.user_properties.entrypoint) {
// If no entrypoint is specified, use the service name or client_id
// as the entrypoint to minimize occurrences of "entrypoint=none"
// results in Amplitude. service name is preferred because
// it's human readable.
// See https://github.com/mozilla/fxa-content-server/issues/6757
if (properties.event_properties.service && properties.event_properties.service !== 'undefined_oauth') {
properties.user_properties.entrypoint = properties.event_properties.service;
} else if (properties.event_properties.oauth_client_id) {
properties.user_properties.entrypoint = properties.event_properties.oauth_client_id;
}
}
return properties;
}
};

Просмотреть файл

@ -294,7 +294,7 @@ describe('metrics/amplitude:', () => {
});
});
describe('transform an event with undefined service:', () => {
describe('transform an event with service=unknown client_id:', () => {
let result;
before(() => {
@ -306,7 +306,29 @@ describe('metrics/amplitude:', () => {
oauth_client_id: 'gribble',
service: 'undefined_oauth'
});
assert.deepEqual(result.user_properties, { '$append': { fxa_services_used: 'undefined_oauth' } });
assert.deepEqual(result.user_properties, {
'$append': { fxa_services_used: 'undefined_oauth' },
entrypoint: 'gribble'
});
});
});
describe('transform an event with service=known client_id:', () => {
let result;
before(() => {
result = transform({ type: 'wibble.blee' }, { service: 'foo' });
});
it('returned the correct event data', () => {
assert.deepEqual(result.event_properties, {
oauth_client_id: 'foo',
service: 'bar'
});
assert.deepEqual(result.user_properties, {
'$append': { fxa_services_used: 'bar' },
entrypoint: 'bar'
});
});
});
@ -319,7 +341,10 @@ describe('metrics/amplitude:', () => {
it('returned the correct event data', () => {
assert.deepEqual(result.event_properties, { service: 'sync' });
assert.deepEqual(result.user_properties, { '$append': { fxa_services_used: 'sync' } });
assert.deepEqual(result.user_properties, {
'$append': { fxa_services_used: 'sync' },
entrypoint: 'sync'
});
});
});