import React from 'react'; import { useMutateKeywordsVolume, useTestAdwordsIntegration } from '../../services/adwords'; import Icon from '../common/Icon'; import SecretField from '../common/SecretField'; type AdWordsSettingsProps = { settings: SettingsType, settingsError: null | { type: string, msg: string }, updateSettings: Function, performUpdate: Function, closeSettings: Function } const AdWordsSettings = ({ settings, settingsError, updateSettings, performUpdate, closeSettings }:AdWordsSettingsProps) => { const { adwords_client_id = '', adwords_client_secret = '', adwords_developer_token = '', adwords_account_id = '', adwords_refresh_token = '', } = settings || {}; const { mutate: testAdWordsIntegration, isLoading: isTesting } = useTestAdwordsIntegration(); const { mutate: getAllVolumeData, isLoading: isUpdatingVolume } = useMutateKeywordsVolume(); const cloudProjectIntegrated = adwords_client_id && adwords_client_secret && adwords_refresh_token; const hasAllCredentials = adwords_client_id && adwords_client_secret && adwords_refresh_token && adwords_developer_token && adwords_account_id; const udpateAndAuthenticate = () => { if (adwords_client_id && adwords_client_secret) { const link = document.createElement('a'); link.href = `https://accounts.google.com/o/oauth2/v2/auth/oauthchooseaccount?access_type=offline&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fadwords&response_type=code&client_id=${adwords_client_id}&redirect_uri=${`${encodeURIComponent(window.location.origin)}/api/adwords`}&service=lso&o2v=2&theme=glif&flowName=GeneralOAuthFlow`; link.target = '_blank'; link.click(); if (performUpdate) { performUpdate(); closeSettings(); } } }; const testIntegration = () => { if (hasAllCredentials) { testAdWordsIntegration({ developer_token: adwords_developer_token, account_id: adwords_account_id }); } }; const updateVolumeData = () => { if (hasAllCredentials) { getAllVolumeData({ domain: 'all' }); } }; return (

Step 1: Connect Google Cloud Project

updateSettings('adwords_client_id', client_id)} value={adwords_client_id} placeholder='3943006-231f65cjm.apps.googleusercontent.com' />
updateSettings('adwords_client_secret', client_secret)} value={adwords_client_secret} placeholder='GTXSPX-45asaf-u1s252sd6qdE9yc8T' />
{!cloudProjectIntegrated &&
}

Step 2: Connect Google Ads

updateSettings('adwords_developer_token', developer_token)} value={adwords_developer_token} placeholder='4xr6jY94kAxtXk4rfcgc4w' />
updateSettings('adwords_account_id', account_id)} value={adwords_account_id} placeholder='590-948-9101' />
{!hasAllCredentials &&
}

Update Keyword Volume Data

Update Volume data for all your Tracked Keywords.

Relevant Documentation: Integrate Google Ads.

); }; export default AdWordsSettings;