@ -8,11 +8,32 @@ import numberFormatter from '../../number-formatter'
import * as api from '../../api'
import LazyLoader from '../../lazy-loader'
const MOBILE _UPPER _WIDTH = 767
const DEFAULT _WIDTH = 1080
export default class Conversions extends React . Component {
constructor ( props ) {
super ( props )
this . state = { loading : true }
this . state = {
loading : true ,
viewport : DEFAULT _WIDTH ,
}
this . onVisible = this . onVisible . bind ( this )
this . handleResize = this . handleResize . bind ( this ) ;
}
componentDidMount ( ) {
window . addEventListener ( 'resize' , this . handleResize , false ) ;
this . handleResize ( ) ;
}
componentWillUnmount ( ) {
window . removeEventListener ( 'resize' , this . handleResize , false ) ;
}
handleResize ( ) {
this . setState ( { viewport : window . innerWidth } ) ;
}
onVisible ( ) {
@ -26,6 +47,11 @@ export default class Conversions extends React.Component {
}
}
getBarMaxWidth ( ) {
const { viewport } = this . state ;
return viewport > MOBILE _UPPER _WIDTH ? "16rem" : "10rem" ;
}
fetchConversions ( ) {
api . get ( ` /api/stats/ ${ encodeURIComponent ( this . props . site . domain ) } /conversions ` , this . props . query )
. then ( ( res ) => this . setState ( { loading : false , goals : res } ) )
@ -33,32 +59,39 @@ export default class Conversions extends React.Component {
renderGoalText ( goalName ) {
if ( this . props . query . period === 'realtime' ) {
return < span className = "block px-2 " style = { { marginTop : '-26px' } } > { goalName } < / s p a n >
return < span className = "block px-2 py-1.5 relative z-9 break-words dark:text-gray-200" > { goalName } < / s p a n >
} else {
const query = new URLSearchParams ( window . location . search )
query . set ( 'goal' , goalName )
return (
< Link to = { { pathname : window . location . pathname , search : query . toString ( ) } } style= { { marginTop : '-26px' } } className= "block px-2 hover:underline">
< Link to = { { pathname : window . location . pathname , search : query . toString ( ) } } className= "block px-2 py-1.5 hover:underline relative z-9 break-words dark:text-gray-200 ">
{ goalName }
< / L i n k >
)
}
}
renderGoal ( goal ) {
const { viewport } = this . state ;
const renderProps = this . props . query . filters [ 'goal' ] == goal . name && goal . prop _names
return (
< div className = "my-2 text-sm" key = { goal . name } >
< div className = "flex items-center justify-between my-2" >
< div className = "relative w-full h-8 dark:text-gray-300" style = { { maxWidth : 'calc(100% - 16rem)' } } >
< Bar count = { goal . count } all = { this . state . goals } bg = "bg-red-50 dark:bg-gray-500 dark:bg-opacity-15" / >
< Bar
count = { goal . count }
all = { this . state . goals }
bg = "bg-red-50 dark:bg-gray-500 dark:bg-opacity-15"
maxWidthDeduction = { this . getBarMaxWidth ( ) }
>
{ this . renderGoalText ( goal . name ) }
< / d i v >
< / Ba r >
< div className = "dark:text-gray-200" >
< span className = "inline-block w-20 font-medium text-right" > { numberFormatter ( goal . count ) } < / s p a n >
< span className = "inline-block w-20 font-medium text-right" > { numberFormatter ( goal . total _count ) } < / s p a n >
{ viewport > MOBILE _UPPER _WIDTH && < span className = "inline-block w-20 font-medium text-right" > { numberFormatter ( goal . total _count ) } < / s p a n > }
< span className = "inline-block w-20 font-medium text-right" > { goal . conversion _rate } % < / s p a n >
< / d i v >
< / d i v >
@ -68,6 +101,7 @@ export default class Conversions extends React.Component {
}
renderInner ( ) {
const { viewport } = this . state ;
if ( this . state . loading ) {
return < div className = "mx-auto my-2 loading" > < div > < / d i v > < / d i v >
} else if ( this . state . goals ) {
@ -78,7 +112,7 @@ export default class Conversions extends React.Component {
< span > Goal < / s p a n >
< div className = "text-right" >
< span className = "inline-block w-20" > Uniques < / s p a n >
< span className = "inline-block w-20" > Total < / s p a n >
{ viewport > MOBILE _UPPER _WIDTH && < span className = "inline-block w-20" > Total < / s p a n > }
< span className = "inline-block w-20" > CR < / s p a n >
< / d i v >
< / d i v >