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' import LazyLoader from '../../components/lazy-loader' export default class SearchTerms extends React.Component { constructor(props) { super(props) this.state = {loading: true} this.onVisible = this.onVisible.bind(this) this.fetchSearchTerms = this.fetchSearchTerms.bind(this) } onVisible() { this.fetchSearchTerms() if (this.props.query.period === 'realtime') { document.addEventListener('tick', this.fetchSearchTerms) } } componentDidUpdate(prevProps) { if (this.props.query !== prevProps.query) { this.setState({loading: true, terms: null}) this.fetchSearchTerms() } } componentWillUnmount() { document.removeEventListener('tick', 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 })).catch((error) => { this.setState({ loading: false, searchTerms: [], notConfigured: true, error: true, isAdmin: error.payload.is_admin }) } ) } renderSearchTerm(term) { return (
Please click below to connect your Search Console account.
>}