Skip to content

Instantly share code, notes, and snippets.

@malliapi
Created October 15, 2020 16:24
Show Gist options
  • Save malliapi/15df7da5195c3b256194aa06925d5d39 to your computer and use it in GitHub Desktop.
Save malliapi/15df7da5195c3b256194aa06925d5d39 to your computer and use it in GitHub Desktop.
Analytics Utils HOC
import React from 'react';
import { trackEvent } from './tealium';
const getDisplayName = Component => Component.displayName || Component.name || 'Component';
export function withAnalytics(OriginalComponent) {
const WithAnalytics = props => <OriginalComponent {...props} track={trackEvent} />;
WithAnalytics.displayName = `WithAnalytics(${getDisplayName(OriginalComponent)})`;
WithAnalytics.WrappedComponent = OriginalComponent;
return WithAnalytics;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment