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 (
Update Volume data for all your Tracked Keywords.
Relevant Documentation: Integrate Google Ads.