File size: 1,154 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import debugFactory from 'debug';
import PropTypes from 'prop-types';
import { Component } from 'react';
import { connect } from 'react-redux';
import { bumpStat, recordTracksEvent } from 'calypso/state/analytics/actions';

/**
 * Module variables
 */
const debug = debugFactory( 'calypso:analytics:TrackComponentView' );

class TrackComponentView extends Component {
	static propTypes = {
		eventName: PropTypes.string,
		eventProperties: PropTypes.object,
		recordTracksEvent: PropTypes.func,
		bumpStat: PropTypes.func,
	};

	static defaultProps = {
		recordTracksEvent: () => {},
		bumpStat: () => {},
	};

	componentDidMount() {
		debug( 'Component did mount.' );
		const { eventName, eventProperties } = this.props;
		if ( eventName ) {
			debug( `Recording Tracks event "${ eventName }".` );
			this.props.recordTracksEvent( eventName, eventProperties );
		}

		const { statGroup, statName } = this.props;
		if ( statGroup ) {
			debug( `Bumping stat "${ statName }".` );
			this.props.bumpStat( statGroup, statName );
		}
	}

	render() {
		return null;
	}
}

export default connect( null, { bumpStat, recordTracksEvent } )( TrackComponentView );