UNPKG

@kiwicom/smart-faq

Version:

Smart FAQ

36 lines (27 loc) 736 B
// @flow strict import * as React from 'react'; import { track } from '../tracker'; import type { CuckooAction, CuckooProps, Subcategory } from '../cuckooTypes'; type Props = {| subcategory: Subcategory, action: CuckooAction, props?: CuckooProps, |}; // TODO ship this into nitrolib export default class LogUnmount extends React.Component<Props> { openedAt: number; static defaultProps = { props: {}, }; componentDidMount() { this.openedAt = Date.now(); } componentWillUnmount() { const { subcategory, action, props } = this.props; const timeOpen = Math.round((Date.now() - this.openedAt) / 1000); track(subcategory, action, { ...props, timeOpen }); } render() { return null; } }