Skip to content

Instantly share code, notes, and snippets.

@sryan-mp
Created June 10, 2021 22:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sryan-mp/fc8e1254801f1055a5e3b2416ae08645 to your computer and use it in GitHub Desktop.
Save sryan-mp/fc8e1254801f1055a5e3b2416ae08645 to your computer and use it in GitHub Desktop.
Analytics.js
import { PureComponent } from 'react';
import PropTypes from 'prop-types';
import { gaPageView, mpPageView, mpFormSubmitted, mpContentDownloaded } from 'utils/analytics';
export default class Analytics extends PureComponent {
static propTypes = {
location: PropTypes.object,
};
componentWillReceiveProps(newProps) {
if (newProps.location.pathname !== this.props.location.pathname) {
this.trackPageView(newProps.location);
}
}
componentDidMount() {
const { location } = this.props;
window.addEventListener('message', mpFormSubmitted);
}
trackPageView(location) {
gaPageView(location.pathname);
mpPageView();
}
contentDownloaded(location){
mpContentDownloaded(location.pathname)
}
render() {
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment