Files
flipper/src/utils/InteractionTracker.js
John Knox 7120bf1201 Use global logger in InteractionTracker
Summary: This tracker isn't really used, but at least now it can benefit from having the sessionId.

Reviewed By: passy

Differential Revision: D13671367

fbshipit-source-id: 3a79e843e3fabab191d0d7471d56a81b1a91a1e9
2019-01-15 09:46:11 -08:00

40 lines
985 B
JavaScript

/**
* Copyright 2018-present Facebook.
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* @format
*/
import {getInstance as getLogger} from '../fb-stubs/Logger';
export function reportInteraction(
componentType: string,
componentIdentifier: string,
) {
const tracker = new InteractionTracker(componentType, componentIdentifier);
return tracker.interaction.bind(tracker);
}
class InteractionTracker {
static numberOfInteractions = 0;
type: string;
id: string;
interaction: (name: string, data: any) => void;
constructor(componentType: string, componentIdentifier: string) {
this.type = componentType;
this.id = componentIdentifier;
}
interaction = (name: string, data: any) => {
getLogger().track('usage', 'interaction', {
interaction: InteractionTracker.numberOfInteractions++,
type: this.type,
id: this.id,
name,
data,
});
};
}