UNPKG

@atlaskit/profilecard

Version:

A React component to display a card with user information.

69 lines (67 loc) 2.92 kB
import { getPageTime } from './performance'; /** Below lines are copied from teams common analytics */ const ANALYTICS_CHANNEL = 'peopleTeams'; const runItLater = cb => { const requestIdleCallback = window.requestIdleCallback; if (typeof requestIdleCallback === 'function') { return requestIdleCallback(cb); } if (typeof window.requestAnimationFrame === 'function') { return window.requestAnimationFrame(cb); } return () => setTimeout(cb); }; export const fireEvent = (createAnalyticsEvent, body) => { if (!createAnalyticsEvent) { return; } runItLater(() => { createAnalyticsEvent(body).fire(ANALYTICS_CHANNEL); }); }; /** Above lines are copied from teams common analytics */ const TEAM_SUBJECT = 'teamProfileCard'; const USER_SUBJECT = 'profilecard'; const AGENT_SUBJECT = 'rovoAgentProfilecard'; const createEvent = (eventType, action, actionSubject, actionSubjectId, attributes = {}) => ({ eventType, action, actionSubject, actionSubjectId, attributes: { packageName: "@atlaskit/profilecard", packageVersion: "23.8.0", ...attributes, firedAt: Math.round(getPageTime()) } }); const getActionSubject = type => { switch (type) { case 'user': return USER_SUBJECT; case 'team': return TEAM_SUBJECT; case 'agent': return AGENT_SUBJECT; default: return 'user'; } }; export const cardTriggered = (type, method, teamId) => { return createEvent('ui', 'triggered', getActionSubject(type), undefined, { method, ...(type === 'team' && teamId ? { teamId } : {}) }); }; export const teamRequestAnalytics = (action, attributes) => createEvent('operational', action, TEAM_SUBJECT, 'request', attributes); export const userRequestAnalytics = (action, attributes) => createEvent('operational', action, USER_SUBJECT, 'request', attributes); export const profileCardRendered = (type, actionSubjectId, attributes) => createEvent('ui', 'rendered', getActionSubject(type), actionSubjectId, attributes); export const actionClicked = (type, attributes) => createEvent('ui', 'clicked', getActionSubject(type), 'action', attributes); export const reportingLinesClicked = attributes => createEvent('ui', 'clicked', USER_SUBJECT, 'reportingLines', attributes); export const moreActionsClicked = (type, attributes) => createEvent('ui', 'clicked', getActionSubject(type), 'moreActions', attributes); export const teamAvatarClicked = attributes => createEvent('ui', 'clicked', TEAM_SUBJECT, 'avatar', attributes); export const moreMembersClicked = attributes => createEvent('ui', 'clicked', TEAM_SUBJECT, 'moreMembers', attributes); export const errorRetryClicked = attributes => createEvent('ui', 'clicked', TEAM_SUBJECT, 'errorRetry', attributes); export const agentRequestAnalytics = (action, actionSubjectId, attributes) => createEvent('operational', action, AGENT_SUBJECT, actionSubjectId || 'request', attributes);