import React from "react";
import { Link, withRouter } from 'react-router-dom'
import Modal from './modal'
import * as api from '../../api'
import numberFormatter from '../../number-formatter'
import Bar from '../bar'
import {parseQuery, toHuman} from '../../query'
import RocketIcon from './rocket-icon'
class GoogleKeywordsModal extends React.Component {
constructor(props) {
super(props)
this.state = {
loading: true,
query: parseQuery(props.location.search, props.site)
}
}
componentDidMount() {
api.get(`/api/stats/${this.props.site.domain}/referrers/Google`, this.state.query, {limit: 100})
.then((res) => this.setState({
loading: false,
searchTerms: res.search_terms,
totalVisitors: res.total_visitors,
notConfigured: res.not_configured,
isOwner: res.is_owner
}))
}
renderTerm(term) {
return (
)
}
renderKeywords() {
if (this.state.query.filters.goal) {
return (
Sorry, we cannot show which keywords converted best for goal {this.state.query.filters.goal}
Google has a monopoly on that data which helps them dominate the analytics market
)
} else if (this.state.notConfigured) {
if (this.state.isOwner) {
return (
The site is not connected to Google Search Keywords
Configure the integration to view search terms
Connect with Google
)
} else {
return (
The site is not connected to Google Search Kewyords
Cannot show search terms
)
}
} else if (this.state.searchTerms.length > 0) {
return (
{ this.state.searchTerms.map(this.renderTerm.bind(this)) }
)
} else {
return (
Could not find any search terms for this period
)
}
}
renderBody() {
if (this.state.loading) {
return (
)
} else {
return (
{this.state.totalVisitors} new visitors from Google
{toHuman(this.state.query)}
Search term
Visitors
{ this.renderKeywords() }
)
}
}
render() {
return (
{ this.renderBody() }
)
}
}
export default withRouter(GoogleKeywordsModal)