Back to Blog

AI-Powered Google Maps Lead Generation with n8n

N8nPort
AI-Powered Google Maps Lead Generation with n8n

Activate this automation on N8nPort with one click

We have completed the workflow installation, node configuration, and setup for you, so the automation is ready to activate without a manual import or node-by-node configuration.

Activate on N8nPort

Quick answers

What kind of information can this workflow collect?

This workflow is designed to collect professional business data, including business names, addresses, phone numbers, websites, and other relevant contact details from Google Maps and associated websites.

How does the workflow ensure data accuracy and avoid duplicates?

The AI agent is instructed to validate and correctly format all data, and to check Google Sheets for existing information before performing new scraping, helping to prevent duplicates.

What happens if the initial scraping results are incomplete?

If the initial scraping provides incomplete results, the workflow can suggest using an internet search tool, like SerpAPI, to enrich the data and gather additional information.

Is this workflow suitable for personal data collection?

No, the workflow is designed to only extract publicly accessible professional data and is explicitly instructed not to collect or store personal or sensitive information, adhering to ethical scraping guidelines.

Quick Overview: Automating Business Lead Collection

This n8n workflow helps you gather business leads from Google Maps and related websites. It uses an AI agent to understand your requests, then scrapes public business information like names, addresses, phone numbers, and websites. All the collected data is then saved into a Google Sheet, providing an organized way to manage your leads.

Key Questions About This Workflow

  • What kind of information can this workflow collect?

    This workflow is designed to collect professional business data, including business names, addresses, phone numbers, websites, and other relevant contact details from Google Maps and associated websites.

  • How does the workflow ensure data accuracy and avoid duplicates?

    The AI agent is instructed to validate and correctly format all data, and to check Google Sheets for existing information before performing new scraping, helping to prevent duplicates.

  • What happens if the initial scraping results are incomplete?

    If the initial scraping provides incomplete results, the workflow can suggest using an internet search tool, like SerpAPI, to enrich the data and gather additional information.

  • Is this workflow suitable for personal data collection?

    No, the workflow is designed to only extract publicly accessible professional data and is explicitly instructed not to collect or store personal or sensitive information, adhering to ethical scraping guidelines.

What This Workflow Does

This n8n workflow creates an automated system for generating business leads. It acts as an AI-powered assistant that can understand natural language requests to find businesses in specific locations and categories. For example, you could ask it to "Find coffee shops in Paris, France." The workflow then uses various tools to scrape data from Google Maps and, if needed, crawl individual business websites for more details. Finally, it organizes all this extracted information into a Google Sheet, making it easy to review and use for your lead generation efforts.

How It Works

The core of this workflow is an AI agent that manages the lead collection process. Here's a breakdown of the steps:

1. Initiating the Request

The workflow starts with a Chat Trigger node. This node listens for user messages, allowing you to interact with the AI agent by simply typing your request, such as "Find plumbers in Berlin, Germany."

2. AI Agent Processing

An AI Agent node, named "Lead Collection," takes your request. This agent is configured with a detailed system message that guides its actions. It understands the task of collecting business leads, knows which tools to use, and follows ethical guidelines for data extraction. It prioritizes accuracy and efficiency, aiming to avoid unnecessary searches.

3. Language Model and Memory

The AI Agent uses an Lm Chat Open Ai node (specifically, the GPT-4o model) to generate and process requests. This large language model helps the agent interpret your input and decide the best course of action. A Memory - Track Recent Context node helps the agent remember previous parts of your conversation, allowing for more coherent interactions.

4. Utilizing Specialized Tools

The AI Agent has access to several specialized tools, often implemented as subworkflows:

  • Tool - Scrape Google Maps Business Data: This tool is a subworkflow designed to extract data from Google Maps. It requires specific inputs like the city, search term (e.g., "restaurant"), and a two-letter ISO 3166 Alpha-2 country code (e.g., "us" for United States). It uses an Http Request node to interact with an external Google Maps Scraper service (like Apify) to gather business names, addresses, phone numbers, and websites.

  • Tool - Crawl Business Website: If more detailed information is needed from a specific business, the agent can use this tool. It's another subworkflow that takes a raw URL and uses an Http Request node to interact with an external Website Content Crawler service (like Apify). This helps extract rich, structured content from the website.

  • Fallback - Enrich with Google Search: If the scraping results are incomplete or if the agent needs additional context, it can use a Tool Serp API node. This node allows the agent to perform general internet searches to enrich the collected data.

5. Data Storage and Aggregation

Once data is extracted, whether from Google Maps or a business website, it's saved. The workflow uses Google Sheets nodes to append the collected business listings or website content to a specified spreadsheet. An Aggregate node then collects all the extracted items before the workflow completes its task, ensuring all data is consolidated.

6. Ethical and Data Handling Guidelines

The AI agent is programmed with strict ethical guidelines. It only extracts publicly accessible professional data and avoids collecting or storing personal or sensitive information. It also checks Google Sheets for existing data to prevent duplicates and suggests alternative actions if scraping fails or returns incomplete results.

Prerequisites

To set up and run this workflow, you'll need access to a few external services and their corresponding credentials:

  • n8n Instance: A running n8n instance where you can import and configure the workflow.

  • Google Account: For using Google Sheets to store your leads. You'll need to set up a Google Sheets OAuth2 credential in n8n to allow the workflow to access your spreadsheets.

  • OpenAI Account: To use the GPT-4o language model. You'll need an Open Ai API credential or an OpenAI API key configured in n8n.

  • SerpAPI Account: For the fallback internet search functionality. You'll need a Serp API credential in n8n.

  • Apify Account: The workflow uses HTTP Request nodes to interact with Apify actors for Google Maps scraping and website content crawling. You will need an Apify API token, which will be configured as a Service-specific API credential (a bearer token) within the HTTP Request nodes.

How You Set It Up

Setting up this workflow involves importing it into your n8n instance and then configuring the necessary credentials and external services. Here's a general guide:

1. Import the Workflow

First, import the workflow JSON into your n8n instance. You can usually do this through the n8n UI by creating a new workflow and pasting the JSON code.

2. Configure Google Sheets Credentials

Locate the Google Sheets nodes in the workflow. You'll need to create or select an existing Google Sheets OAuth2 credential. This involves authenticating your Google account with n8n, granting it permission to manage your spreadsheets. Once authenticated, specify the Document ID and Sheet Name where you want the leads to be saved.

3. Set Up OpenAI Credentials

Find the Lm Chat Open Ai node. Here, you'll need to provide your Open Ai API credential or OpenAI API key. This typically involves entering your API key obtained from your OpenAI account dashboard.

4. Configure SerpAPI Credentials

For the Fallback - Enrich with Google Search node (which uses Tool Serp API), you'll need to set up your Serp API credential. This involves entering your API key from your SerpAPI account.

5. Configure Apify API Tokens

The workflow uses Http Request nodes to interact with Apify for Google Maps and website scraping. In these nodes, you'll find a header parameter for "Authorization" with a value like "Bearer <token>" or "Bearer YOUR_TOKEN_HERE." Replace the placeholder with your actual Apify API token. This token acts as a Service-specific API credential for Apify.

6. Review Subworkflows

This main workflow uses two subworkflows: "Google Maps - sous 1 - Extract Google maps" and "Google Maps - sous 2 - Extract Google." Ensure these subworkflows are also imported and correctly linked within the main workflow's Tool Workflow nodes. The subworkflows themselves contain the Http Request nodes for Apify, so ensure their Apify tokens are also configured.

7. Activate the Workflow

After configuring all credentials and settings, save the workflow and activate it. You can then interact with it via the Chat Trigger node.

Ready to automate?

The complete installation and configuration are already prepared for your workspace. Activate the preconfigured workflow on N8nPort with one click.

Activate the workflow

Customization Ideas

This workflow offers several points for customization to better suit your specific lead generation needs:

  • Adjust AI Agent Prompt: You can modify the system message within the "AI Agent - Lead Collection" node to refine how the agent interprets requests, prioritizes data, or interacts with users. For example, you could instruct it to focus on specific types of contact information or to summarize results in a particular format.

  • Change Google Sheets Output: Customize the columns and structure of your Google Sheet. You can map specific data fields from the scraping results to different columns in your spreadsheet for better organization.

  • Modify Scraping Parameters: In the Google Maps scraping subworkflow, you can adjust parameters like maxCrawledPlacesPerSearch to control the number of businesses scraped per query. You might also add more specific filters if the underlying Apify actor supports them.

  • Integrate Other Data Sources: Extend the AI agent's capabilities by adding more tools. For instance, you could integrate a tool for checking business social media profiles or for validating email addresses.

  • Add Notification Systems: Incorporate nodes to send notifications (e.g., email, Slack, Discord) when a scraping job is complete, or if an error occurs, keeping you informed about the workflow's progress.

Limitations and Troubleshooting

While powerful, this workflow has some considerations:

  • External Service Dependencies: The workflow relies on external services like OpenAI, SerpAPI, and Apify. Any issues with these services, such as API rate limits, service outages, or changes in their APIs, can affect the workflow's operation.

  • Data Quality: The quality of scraped data depends on the public information available on Google Maps and business websites. Not all businesses may have complete or up-to-date information. The AI agent is designed to suggest alternative actions for incomplete results, such as using internet search.

  • Country Code Format: The Google Maps Scraper specifically requires country codes in ISO 3166 Alpha-2 lowercase format (e.g., "fr" for France). Incorrect formatting will lead to failed searches.

  • URL Handling: When providing URLs for website scraping, they must be passed exactly as received, without quotation marks or modifications, to ensure the Website Scraper tool functions correctly.

  • Ethical Compliance: Always ensure your use of this workflow complies with the terms of service of Google Maps, Apify, and any other services, as well as relevant data protection regulations. The workflow is designed to only collect publicly accessible professional data.

  • Troubleshooting: If the workflow encounters issues, check the execution logs in n8n for specific error messages. Verify that all API keys and credentials are correctly configured and that external services are operational. Review the AI agent's prompt for any unintended constraints or instructions.

Frequently Asked Questions

What is the primary goal of this n8n workflow?

The primary goal is to automate the collection of professional business leads from Google Maps and associated websites, organizing the extracted data into Google Sheets.

Which AI model is used in this workflow?

The workflow uses the GPT-4o model from OpenAI for its language model capabilities, enabling the AI agent to understand and process user requests.

How does the workflow handle existing data in Google Sheets?

The AI agent is instructed to check Google Sheets for existing data before performing new scraping, helping to avoid duplicate entries.

What is the role of Apify in this workflow?

Apify provides the underlying scraping services for both Google Maps data extraction and website content crawling, which are accessed via HTTP Request nodes within the n8n workflow.

Can I use this workflow to scrape data from any website?

The workflow includes a tool for crawling business websites based on a provided URL. However, its effectiveness depends on the website's structure and the capabilities of the underlying website content crawler service.

What should I do if the workflow fails to find businesses?

Check that the location, business type, and country code (in ISO 3166 Alpha-2 lowercase format) are correctly provided in your request. Also, verify your Apify credentials and ensure the external scraping service is operational.

Source and Next Steps

This workflow was originally shared by the n8n community. You can find the source workflow and more details at: https://n8n.io/workflows/3443

To explore further, consider experimenting with the customization ideas, adapting the AI agent's prompt, or integrating additional tools to enhance its lead generation capabilities.

Activate this workflow on N8nPort

Choose your workspace and activate the fully prepared automation with one click.

Activate on N8nPort