import React from 'react'; import FadeIn from '../../fade-in' import Bar from '../bar' import MoreLink from '../more-link' import numberFormatter from '../../util/number-formatter' import RocketIcon from '../modals/rocket-icon' import * as api from '../../api' export default class SearchTerms extends React.Component { constructor(props) { super(props) this.state = {loading: true} } componentDidMount() { this.fetchSearchTerms() } componentDidUpdate(prevProps) { if (this.props.query !== prevProps.query) { this.setState({loading: true, terms: null}) this.fetchSearchTerms() } } fetchSearchTerms() { api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/referrers/Google`, this.props.query) .then((res) => this.setState({ loading: false, searchTerms: res.search_terms || [], notConfigured: res.not_configured, isAdmin: res.is_admin })) } renderSearchTerm(term) { return (
{ term.name } {numberFormatter(term.visitors)}
) } renderList() { if (this.props.query.filters.goal) { return (
Sorry, we cannot show which keywords converted best for goal {this.props.query.filters.goal}
Google does not share this information
) } else if (this.state.notConfigured) { return (
The site is not connected to Google Search Keywords
Cannot show search terms
{this.state.isAdmin && Connect with Google }
) } else if (this.state.searchTerms.length > 0) { const valLabel = this.props.query.period === 'realtime' ? 'Current visitors' : 'Visitors' return (
Search term {valLabel}
{this.state.searchTerms.map(this.renderSearchTerm.bind(this))}
) } else { return (
Could not find any search terms for this period
Google Search Console data is sampled and delayed by 24-36h
Read more on our documentation
) } } renderContent() { if (this.state.searchTerms) { return (

Search Terms

{ this.renderList() }
) } } render() { return (
{ this.state.loading &&
} { this.renderContent() }
) } }