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() { if (this.state.query.filters.goal) { api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/goal/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 })) } else { api.get(`/api/stats/${encodeURIComponent(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 ( {term.name} {numberFormatter(term.count)} ) } renderKeywords() { if (this.state.query.filters.goal) { return (
Sorry, we cannot show which keywords converted best for goal {this.state.query.filters.goal}
Google does not share this information
) } 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))}
Search Term Visitors
) } else { return (
Could not find any search terms for this period
) } } renderGoalText() { if (this.state.query.filters.goal) { return (

completed {this.state.query.filters.goal}

) } } renderBody() { if (this.state.loading) { return (
) } else { return ( ← All referrers

{this.state.totalVisitors} visitors from Google
{toHuman(this.state.query)}

{this.renderGoalText()} { this.renderKeywords() }
) } } render() { return ( { this.renderBody() } ) } } export default withRouter(GoogleKeywordsModal)