Skip to main content
RapidDev - Software Development Agency
lovable-integrationsEdge Function Integration

How to Integrate Lovable with SpyFu

To integrate SpyFu with Lovable, create Supabase Edge Functions that authenticate using SpyFu's API key, then proxy calls to SpyFu's REST API for competitor PPC keyword data, ad history, and domain analytics. Store your API key in Cloud Secrets to build competitive intelligence dashboards in Lovable.

What you'll learn

  • How to obtain and configure a SpyFu API key for Edge Function authentication
  • How to create a Supabase Edge Function that proxies SpyFu API calls for competitor keyword and ad data
  • How to build a PPC competitive intelligence dashboard showing competitor keyword overlap and ad spend estimates
  • How to query SpyFu's domain ad history API to research competitor Google Ads strategies
  • How to surface competitive keyword insights in a Lovable application for media buyers and marketing strategists
Book a free consultation
4.9Clutch rating
600+Happy partners
17+Countries served
190+Team members
Intermediate14 min read60 minutesMarketingMarch 2026RapidDev Engineering Team
TL;DR

To integrate SpyFu with Lovable, create Supabase Edge Functions that authenticate using SpyFu's API key, then proxy calls to SpyFu's REST API for competitor PPC keyword data, ad history, and domain analytics. Store your API key in Cloud Secrets to build competitive intelligence dashboards in Lovable.

Build PPC Competitive Intelligence Dashboards in Lovable with SpyFu

Understanding what competitors spend on Google Ads, which keywords they bid on, and what ad copy they use is invaluable for any PPC strategy. SpyFu has been collecting and indexing this competitive intelligence data for over a decade, making it one of the richest sources of historical Google Ads data available. Building a custom Lovable application connected to SpyFu's API lets your team research competitors on demand, track their advertising patterns over time, and identify keyword opportunities your competitors are missing.

SpyFu's API exposes domain-level analytics that include estimated monthly Google Ads spend, number of paid keywords, ad copy history, organic keyword rankings, and keyword overlap analysis. The competitor overlap feature is particularly powerful — it shows which keywords both you and your competitors are bidding on (and at what positions), which keywords they have but you are missing, and vice versa. This data powers strategic decisions about where to increase bids, where to expand coverage, and which competitors to prioritize monitoring.

The integration is relatively straightforward compared to OAuth2-based platforms. SpyFu uses a simple API key authentication that requires the key as a query parameter on every request. The Edge Function pattern is important here: if the key were used directly in frontend code, anyone viewing your application's network requests could extract it and use it against your SpyFu quota. Routing all calls through an Edge Function keeps the key hidden while still delivering the competitive intelligence data to your dashboard.

Integration method

Edge Function Integration

SpyFu integration in Lovable uses Supabase Edge Functions that authenticate via SpyFu's API key passed as a query parameter or request header. Edge Functions proxy all SpyFu API requests, keeping the API key encrypted in Cloud Secrets and accessible only via Deno.env.get(). React components in your Lovable app receive competitive intelligence data without the API key ever appearing in browser network requests.

Prerequisites

  • A SpyFu account on a paid plan — the API is available on Professional and Team plans, not on the free plan
  • A SpyFu API key — generated from your SpyFu account settings under Account → API Access
  • A Lovable project with Lovable Cloud enabled
  • A list of competitor domains you want to research (e.g., competitor.com — just the domain without https://)
  • Optional: your own Google Ads keyword list to compare against competitor data for gap analysis

Step-by-step guide

1

Obtain your SpyFu API key

Log in to your SpyFu account at spyfu.com and navigate to your account settings by clicking your username or avatar in the top right corner, then selecting 'Account Settings' or 'My Account'. Look for an 'API' or 'API Access' section within your account settings. If you do not see an API option, verify that your plan includes API access — SpyFu's API is available on Professional ($39/month) and Team ($78/month) plans. If you are on the Basic plan, you will need to upgrade to access the API. In the API Access section, you will find your API key or a button to generate one. Click 'Generate API Key' if it has not been created yet. Copy the key, which is a long alphanumeric string. SpyFu's API key grants access to domain analytics, keyword data, and ad history queries, scoped by your plan's monthly query limits. The Professional plan typically includes a set number of API rows per month — check your plan details to understand your quota. The API key does not expire automatically but can be regenerated if compromised. Unlike OAuth2, there is no token refresh cycle. Store the key immediately in Cloud Secrets rather than saving it in a text file where it might get accidentally committed or shared.

Pro tip: SpyFu API queries consume your monthly row quota. Each API call that returns data rows counts against your limit. Build caching into your application to avoid re-querying the same domains repeatedly throughout the day.

Expected result: You have a SpyFu API key copied and ready to store in Cloud Secrets.

2

Store the SpyFu API key in Cloud Secrets

In your Lovable project, open the Cloud tab by clicking '+' next to the Preview panel, then navigate to the Secrets section. Click 'Add Secret' and create a new secret named SPYFU_API_KEY with your API key as the value. This single credential is all that SpyFu requires for authentication. SpyFu's API typically accepts the key as a query parameter named api_key appended to every request URL — this is why storing it in an Edge Function secret is especially important. If it were used directly in frontend code, the key would be visible in every browser network request anyone makes to your Lovable app, visible in the browser's developer tools network tab and in any network monitoring tool. Routing through an Edge Function keeps the key on the server side where it belongs. Lovable's automated security infrastructure blocks approximately 1,200 hardcoded API keys per day from leaking into application code — but the strongest protection is the architectural decision to always use Cloud Secrets and Edge Functions for authenticated API calls. After saving the secret, verify it by checking the Secrets list in the Cloud tab and confirming SPYFU_API_KEY appears. The value will be masked with asterisks for security, but you can verify the secret name is correct.

Pro tip: SpyFu API keys are tied to your account's monthly quota. If you need to test the integration, use a minimal date range and a single domain to avoid consuming quota unnecessarily during development.

Expected result: SPYFU_API_KEY is stored in Cloud Secrets and ready for use in the Edge Function.

3

Create the SpyFu API proxy Edge Function

Ask Lovable to create a Supabase Edge Function called spyfu-api that accepts an endpoint path and optional query parameters, then appends the API key and proxies the request to SpyFu's API. SpyFu's API base URL is https://www.spyfu.com/apis/domain_stats_api/v2/ for domain statistics, https://www.spyfu.com/apis/url_api/v2/ for URL-level data, and https://www.spyfu.com/apis/keyword_api/v2/ for keyword data. The API key is passed as a query parameter: ?api_key={key}&format=json. The Edge Function should accept an endpoint string (like 'getDomainStatsForExactDate'), a domain parameter, and any additional query parameters specific to the endpoint. It constructs the URL, appends all parameters including the API key, makes a GET request, and returns the JSON response. Key SpyFu endpoints to support include getDomainStatsForExactDate (domain PPC stats), getTopListFedomain (top keywords for a domain), getAdsForDomain (ad copy history), and getRelatedKeywordsforTerm (keyword research). Validate the domain parameter to ensure it is a plain domain without protocols or trailing slashes before forwarding to SpyFu — SpyFu returns errors or unexpected results for improperly formatted domains. Include an allowlist of the SpyFu API base URL paths to prevent proxy misuse.

Lovable Prompt

Create a Supabase Edge Function called spyfu-api. Read SPYFU_API_KEY from Deno.env.get(). Accept endpoint, domain, and optional extra params in the request JSON. Determine the correct SpyFu API base URL based on the endpoint category. Append the api_key and format=json as query parameters along with the domain and any other params. Make a GET request and return the JSON response. Handle SpyFu API errors and return descriptive messages.

Paste this in Lovable chat

supabase/functions/spyfu-api/index.ts
1import { serve } from "https://deno.land/std@0.168.0/http/server.ts";
2
3const corsHeaders = {
4 "Access-Control-Allow-Origin": "*",
5 "Access-Control-Allow-Headers": "authorization, x-client-info, apikey, content-type",
6};
7
8const ENDPOINT_BASES: Record<string, string> = {
9 domain: "https://www.spyfu.com/apis/domain_stats_api/v2/",
10 keyword: "https://www.spyfu.com/apis/keyword_api/v2/",
11 url: "https://www.spyfu.com/apis/url_api/v2/",
12};
13
14function getBaseUrl(endpoint: string): string {
15 if (endpoint.includes("Keyword") || endpoint.includes("keyword")) return ENDPOINT_BASES.keyword;
16 if (endpoint.includes("Url") || endpoint.includes("url")) return ENDPOINT_BASES.url;
17 return ENDPOINT_BASES.domain;
18}
19
20serve(async (req) => {
21 if (req.method === "OPTIONS") return new Response("ok", { headers: corsHeaders });
22
23 try {
24 const apiKey = Deno.env.get("SPYFU_API_KEY");
25 if (!apiKey) throw new Error("SPYFU_API_KEY not configured");
26
27 const { endpoint, domain, params = {} } = await req.json();
28 if (!endpoint) throw new Error("endpoint is required");
29 if (!domain) throw new Error("domain is required");
30
31 // Validate domain format (no protocol or trailing slash)
32 const cleanDomain = domain.replace(/^https?:\/\//, "").replace(/\/$/, "");
33
34 const baseUrl = getBaseUrl(endpoint);
35 const url = new URL(`${baseUrl}${endpoint}`);
36 url.searchParams.set("api_key", apiKey);
37 url.searchParams.set("format", "json");
38 url.searchParams.set("domain", cleanDomain);
39
40 Object.entries(params as Record<string, string>).forEach(([k, v]) => {
41 url.searchParams.set(k, v);
42 });
43
44 const response = await fetch(url.toString());
45 const data = await response.json();
46
47 if (!response.ok || data.error) {
48 throw new Error(data.error || `SpyFu API error: ${response.status}`);
49 }
50
51 return new Response(JSON.stringify(data), {
52 headers: { ...corsHeaders, "Content-Type": "application/json" },
53 });
54 } catch (error) {
55 return new Response(
56 JSON.stringify({ error: error.message }),
57 { status: 500, headers: { ...corsHeaders, "Content-Type": "application/json" } }
58 );
59 }
60});

Pro tip: Test the Edge Function immediately after deploying by calling it with endpoint 'getDomainStatsForExactDate' and a competitor domain like 'competitor.com'. If you get stats back, the API key and proxy are both working correctly.

Expected result: The spyfu-api Edge Function is deployed and returns SpyFu domain data when called with a valid endpoint and domain.

4

Build the PPC competitor intelligence dashboard

With the Edge Function working, ask Lovable to build a competitive intelligence dashboard. The main SpyFu endpoint for PPC data is getDomainStatsForExactDate, which returns estimated monthly Google Ads spend, number of paid keywords, average ad position, and other metrics for a domain. Start by showing a list of competitor domains as input cards where users can type in competitor domain names. When a user adds a domain, call your Edge Function to fetch stats and display them as a metric card with the domain name, estimated monthly spend, number of paid keywords, and number of organic keywords. For the keyword overlap analysis, the getSharedPaidKeywords endpoint accepts two domains and returns keywords that both are bidding on — use this to build a head-to-head comparison view between your domain and any single competitor. For ad copy research, the getAdsForDomain endpoint returns a list of ad units with headlines and descriptions — display these in a scrollable card grid with the ad headline and description text, and sort by the estimated monthly spend on that keyword to surface the highest-investment ads first. Cache results per domain in React state for the current session to avoid repeat API calls when switching between competitor views.

Lovable Prompt

Build a PPC competitor intelligence dashboard that calls my spyfu-api Edge Function. Create an interface where users can enter up to 5 competitor domains. For each domain, fetch stats from getDomainStatsForExactDate endpoint and show a card with estimated monthly Google Ads spend, number of paid keywords, and number of organic keywords. Add a competitor comparison tab that uses getSharedPaidKeywords to show keyword overlap between my domain and one selected competitor. Add an ad copy tab that calls getAdsForDomain and shows competitor ads in a card grid sorted by estimated keyword spend.

Paste this in Lovable chat

Pro tip: SpyFu estimates are based on their proprietary data modeling and should be treated as directional rather than precise figures. Display a disclaimer on your dashboard noting that spend estimates are approximations.

Expected result: A PPC competitive intelligence dashboard displays competitor domain stats, keyword overlap, and ad copy history with real SpyFu data.

Common use cases

Competitor PPC spend and keyword monitoring dashboard

Track estimated monthly Google Ads spend, number of paid keywords, and top ad copy for a list of competitor domains. See month-over-month changes in competitor ad activity to detect when competitors are scaling up or pulling back advertising, giving you a strategic timing advantage.

Lovable Prompt

Build a competitor PPC monitoring dashboard that calls my spyfu-api Edge Function with a list of competitor domains. For each competitor show their estimated monthly Google Ads spend, number of paid keywords, and top 3 ad copy examples from SpyFu. Display competitors as cards sorted by estimated spend descending. Add an input field to add new competitor domains to monitor. Show a trend indicator if this month's spend estimate is higher or lower than last month.

Copy this prompt to try it in Lovable

Keyword gap analysis tool

Identify keywords that top competitors are bidding on that your brand is not yet targeting. Show each competitor's unique keywords along with their estimated bid, average position, and monthly search volume to help your team prioritize which gaps to close first.

Lovable Prompt

Create a keyword gap analysis page that calls my spyfu-api Edge Function to fetch the top 50 paid keywords for three competitor domains. Compare these against my own domain's paid keywords. Show keywords that competitors have but I do not, with columns for keyword, which competitors bid on it, estimated CPC, and monthly search volume. Sort by monthly search volume descending. Add a button to export the gap keywords as a CSV.

Copy this prompt to try it in Lovable

Ad copy research and inspiration library

Browse the historical ad copy archive for competitor domains to find the ads they have run the longest (indicating they perform well) and the newest tests they are running. Use this to inspire and improve your own ad creative and identify which value propositions competitors are emphasizing.

Lovable Prompt

Build an ad copy research tool that fetches ad history for a domain from my spyfu-api Edge Function using SpyFu's ad history endpoint. Show each ad unit with headline 1, headline 2, description lines, and the date range it ran. Sort by duration descending to show longest-running ads first (most likely winning ads). Add a domain input field so users can research any competitor. Display ads in a card grid format with a copy button for each ad.

Copy this prompt to try it in Lovable

Troubleshooting

SpyFu API returns empty results or 0 values for a domain that has obvious ad activity

Cause: The domain format may include a protocol (https://) or trailing slash that SpyFu does not accept, causing it to not find data for the domain. SpyFu also requires the bare domain without subdomain for most endpoints.

Solution: Strip any protocol prefix (https://, http://) and trailing slashes from domain inputs in your Edge Function before passing to SpyFu. For example, use 'competitor.com' not 'https://www.competitor.com/'. Also try with and without 'www.' prefix as SpyFu may have data under either format.

typescript
1// Clean domain input before calling SpyFu
2const cleanDomain = domain
3 .replace(/^https?:\/\//, '')
4 .replace(/^www\./, '')
5 .replace(/\/$/, '').toLowerCase();

API calls succeed for some domains but return 'quota exceeded' or similar errors after a number of calls

Cause: SpyFu API plans have monthly row quotas. If the dashboard is querying multiple domains without caching, each page load can consume many quota rows quickly, especially for keyword list endpoints that return large datasets.

Solution: Implement caching in your Supabase database for SpyFu responses. Store the domain data with a timestamp and only re-query SpyFu if the cached data is more than 24 hours old. Use Supabase's upsert with a domain+date composite key to keep one record per domain per day.

The Edge Function returns a 500 error with 'SPYFU_API_KEY not configured'

Cause: The secret name in the Edge Function code does not exactly match the secret name in Cloud Secrets, or the secret was not saved correctly.

Solution: In the Cloud tab → Secrets panel, verify the secret is named exactly SPYFU_API_KEY — no spaces, no extra characters. The Deno.env.get() call is case-sensitive and must match exactly. Delete and re-add the secret if there is any doubt about the stored value.

Ad copy results show very old ads from years ago and miss recent competitor campaigns

Cause: The SpyFu ad history API may return a paginated result set where older ads appear first, or the request is not filtering by a recent date range.

Solution: Check if the SpyFu ad history endpoint supports date range parameters and pass startMonth and endMonth parameters to filter to recent results. If the API does not support date filtering, sort the client-side results by last seen date descending and display a note indicating the data goes back to SpyFu's full history.

Best practices

  • Store your SpyFu API key in Cloud Secrets and route all API calls through the Edge Function — SpyFu's API key passes as a URL query parameter, making it especially easy to accidentally expose in browser network requests without a proxy
  • Cache SpyFu API responses in your Supabase database per domain with a 24-hour TTL — SpyFu data is not real-time and does not change more than daily, so repeated queries waste your monthly quota
  • Display spend estimates with a disclaimer that SpyFu figures are proprietary estimates rather than actual spend data — managing stakeholder expectations about data accuracy is important for competitive intelligence tools
  • Validate and clean domain inputs before passing them to the SpyFu API — strip protocols, www prefixes, and trailing slashes to ensure consistent results
  • Limit the number of competitor domains a user can simultaneously monitor to avoid hitting API quotas unexpectedly — a limit of 10-15 domains in a watchlist is reasonable for most plans
  • Combine SpyFu data with your own Google Ads data (via the Google Ads API integration) to create true gap analysis — comparing SpyFu's view of competitor keywords against your actual account's keywords identifies the most actionable opportunities
  • For teams sharing the dashboard, consider pre-computing competitor snapshots on a nightly schedule using a Supabase Edge Function and storing results in the database, rather than fetching live on each user's request

Alternatives

Frequently asked questions

How accurate is SpyFu's estimated monthly Google Ads spend for competitor domains?

SpyFu's spend estimates are directional indicators based on their proprietary data modeling, not exact figures. They are calculated from estimated keyword positions, historical auction data, and average CPC benchmarks. Most practitioners find SpyFu estimates accurate within 20-40% of actual spend, making them useful for ranking competitors by investment level but not for precise budget comparisons. Always present SpyFu spend data as estimates on your dashboard.

Does SpyFu's API cover Bing Ads data or only Google Ads?

SpyFu's primary competitive intelligence data covers Google Ads campaigns. Bing/Microsoft Advertising data coverage is limited or not available through the API. If you need competitor Bing Ads research, you would need a tool that specifically tracks Microsoft Advertising data. SpyFu's strength is its deep historical archive of Google Ads data going back many years.

What is included in SpyFu's API access and which plans support it?

SpyFu API access is available on Professional ($39/month) and Team ($78/month) plans. The API provides access to domain stats, keyword data, ad history, and competitor analysis endpoints. Each plan includes a monthly row quota that limits how much data you can retrieve. The Basic plan does not include API access. Check spyfu.com for current plan details and quota limits.

Can I use the SpyFu API to research my own domain's PPC performance?

Yes, SpyFu's API endpoints work on any domain including your own. This is useful for auditing how SpyFu perceives your own ad activity versus what you know your actual spend to be, and for checking which of your keywords SpyFu has indexed. However, for your own campaign data, your actual Google Ads account via the Google Ads API provides far more accurate and comprehensive data than SpyFu's estimates.

How does building a SpyFu integration in Lovable compare to using SpyFu's native interface?

SpyFu's native interface is optimized for individual domain research sessions. A custom Lovable integration lets you build a watchlist of competitors that updates automatically, combine SpyFu's competitive data with your own Google Ads performance data for true gap analysis, and share insights with teammates who do not have SpyFu accounts. For complex competitive monitoring setups, RapidDev can help architect a more sophisticated data pipeline that combines SpyFu data with your own advertising metrics.

RapidDev

Talk to an Expert

Our team has built 600+ apps. Get personalized help with your project.

Book a free consultation

Need help with your project?

Our experts have built 600+ apps and can accelerate your development. Book a free consultation — no strings attached.

Book a free consultation

We put the rapid in RapidDev

Need a dedicated strategic tech and growth partner? Discover what RapidDev can do for your business! Book a call with our team to schedule a free, no-obligation consultation. We'll discuss your project and provide a custom quote at no cost.