mirror of
https://github.com/oceanprotocol/commons.git
synced 2023-03-15 18:03:00 +01:00
withTracker HOC formatting
This commit is contained in:
parent
18267a1a18
commit
6ac4440897
@ -72,4 +72,9 @@ export const faucetPort = process.env.REACT_APP_FAUCET_PORT || 443
|
|||||||
// export const faucetHost = 'localhost'
|
// export const faucetHost = 'localhost'
|
||||||
// export const faucetPort = 3001
|
// export const faucetPort = 3001
|
||||||
|
|
||||||
export const verbose = true
|
export const verbose = true
|
||||||
|
|
||||||
|
//
|
||||||
|
// APP CONFIG
|
||||||
|
//
|
||||||
|
export const analyticsId = 'UA-60614729-11'
|
||||||
|
@ -252,7 +252,7 @@ class Publish extends Component<{}, PublishState> {
|
|||||||
ReactGA.event({
|
ReactGA.event({
|
||||||
category: 'Publish',
|
category: 'Publish',
|
||||||
action: 'registerAsset-start'
|
action: 'registerAsset-start'
|
||||||
});
|
})
|
||||||
this.setState({
|
this.setState({
|
||||||
publishingError: '',
|
publishingError: '',
|
||||||
isPublishing: true
|
isPublishing: true
|
||||||
|
@ -1,15 +1,19 @@
|
|||||||
import React, { Component } from 'react'
|
import React, { PureComponent } from 'react'
|
||||||
import ReactGA from 'react-ga'
|
import ReactGA from 'react-ga'
|
||||||
|
|
||||||
|
import { analyticsId } from './config/config'
|
||||||
|
|
||||||
interface TrackerProps {
|
interface TrackerProps {
|
||||||
location: any
|
location: Location
|
||||||
}
|
}
|
||||||
|
|
||||||
ReactGA.initialize('UA-60614729-11', {testMode: process.env.NODE_ENV === 'test'})
|
ReactGA.initialize(analyticsId, {
|
||||||
|
testMode: process.env.NODE_ENV === 'test'
|
||||||
|
})
|
||||||
|
|
||||||
export default function withTracker(WrappedComponent: any, options: any = {}) {
|
export default function withTracker(WrappedComponent: any, options: any = {}) {
|
||||||
const trackPage = (page: any) => {
|
const trackPage = (page: string) => {
|
||||||
options.isWeb3 = (window.web3 !== undefined)
|
options.isWeb3 = window.web3 !== undefined
|
||||||
ReactGA.set({
|
ReactGA.set({
|
||||||
page,
|
page,
|
||||||
...options
|
...options
|
||||||
@ -17,25 +21,26 @@ export default function withTracker(WrappedComponent: any, options: any = {}) {
|
|||||||
ReactGA.pageview(page)
|
ReactGA.pageview(page)
|
||||||
}
|
}
|
||||||
|
|
||||||
const HOC = class extends Component<TrackerProps, {}> {
|
return class HOC extends PureComponent<TrackerProps, {}> {
|
||||||
componentDidMount() {
|
public componentDidMount() {
|
||||||
const page = this.props.location.pathname + this.props.location.search
|
const page =
|
||||||
|
this.props.location.pathname + this.props.location.search
|
||||||
trackPage(page)
|
trackPage(page)
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps: any) {
|
public componentWillReceiveProps(nextProps: any) {
|
||||||
const currentPage = this.props.location.pathname;
|
const currentPage = this.props.location.pathname
|
||||||
const nextPage = nextProps.location.pathname;
|
const nextPage = nextProps.location.pathname
|
||||||
|
|
||||||
if (currentPage !== nextPage) {
|
if (currentPage !== nextPage) {
|
||||||
trackPage(nextProps.location.pathname + nextProps.location.search);
|
trackPage(
|
||||||
|
nextProps.location.pathname + nextProps.location.search
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
public render() {
|
||||||
return <WrappedComponent {...this.props} />
|
return <WrappedComponent {...this.props} />
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return HOC
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user