In Part 1 of our series, we walked you through exporting your Google Ads campaigns as a CSV using Google Ads Editor. In this second installment, we dive into the automation of translating your campaigns into multiple languages with a Python script powered by ChatGPT. This guide will help you understand the workflow, review the key components of the script, and learn how to enforce translation quality and character limits.


Overview
Automating translations can save countless hours, enabling you to localize your ads quickly and efficiently. In this session, you’ll learn how to:

  • Leverage a Python script in a Jupyter Notebook environment.
  • Utilize the OpenAI API (ChatGPT) for translating ad copy.
  • Handle data using Pandas and secure your API credentials with dotenv.
  • Enforce Google Ads character limits for headlines, descriptions, and display paths.
  • Prepare your translated campaigns for review before re-uploading in Part 3.


Setting Up the Python Environment
Before running the script, ensure you have the necessary tools and libraries installed:

  1. Jupyter Notebook:
    We use Jupyter Notebook to run and document the script, making it easier to iterate and debug.
  2. Key Python Libraries:
    OpenAI: For accessing the ChatGPT translation model.
    Pandas: For reading, manipulating, and exporting your CSV data.
    dotenv: To securely load your OpenAI API key from an environment file.
  3. API Key Security:
    Your OpenAI API key is stored in an environment file (.env), ensuring that sensitive credentials remain secure.


The Language Dictionary

A critical component of the script is the language dictionary. This mapping allows you to convert Google Ads language names to their corresponding language codes (e.g., Arabic to AR, Spanish to ES). Before running your translations, confirm that your target language is included in this dictionary to prevent any errors during the process.


Input Parameters
The script accepts several inputs:

  • Folder and File Path: The location of your exported Google Ads campaign CSV.
  • Target Language: The language you want to translate your campaign into.
  • Campaign Start Date: The desired start date for the translated campaign.

These inputs allow the script to process the correct file and apply the necessary translations based on your campaign’s requirements.


Selecting the ChatGPT Model and Crafting Prompts

Once the inputs are set, the script:

  • Reloads the API Key: Ensuring secure and authenticated access to OpenAI’s services.
  • Selects a ChatGPT Model: You can choose different models based on your translation needs.
  • Utilizes Custom Prompts:
    Separate prompts are defined for headlines, descriptions, and display paths. These prompts are specifically designed to enforce character limits imposed by Google Ads (for instance, headlines may have a maximum of 30 characters).


Translation Functions and Character Limit Enforcement
The script contains two key functions:

  • Translate Text: This function sends the ad copy to ChatGPT for translation.
  • Rewrite Text with Retry Logic:
    • This function checks if the translated text adheres to character limits.
    • If the output exceeds the allowed length (e.g., a headline exceeding 30 characters), it will retry up to five times.
    • Should the retries fail, the function will truncate the text to ensure compliance with Google Ads requirements.

This robust error handling ensures that your translations are both accurate and optimized for ad performance.


Processing the CSV Data

The next steps involve:

  • Reading the Exported CSV:
    Using Pandas, the script imports your campaign data.
  • Identifying Columns to Translate:
    Key columns include campaign names, ad group headlines, descriptions, display paths, and keywords.
  • Replacing Campaign Start Date and Inserting Language Codes:
    The script updates specific fields to match the target language and campaign schedule.
  • Reviewing Translated Data:
    After processing, the script prints the updated DataFrame for a quick check before exporting the new CSV file.


Quality Assurance and Final Checks

Before moving on to Part 3, it’s crucial to verify that:

  • Translated headlines, descriptions, and keywords read naturally.
  • The character limits are respected.
  • Any necessary adjustments (especially for keywords) are made to reflect how users would naturally search for your products or services in the target language.

This meticulous quality assurance ensures that your localized campaigns are ready to drive engagement and conversions.


What’s Next?

With your campaigns successfully translated using Python and ChatGPT, you’re now ready for the final step: re-uploading the translated CSV back into Google Ads. In Part 3 of this series, we’ll guide you through the process of integrating your newly localized campaigns using Google Ads Editor.


Final Thoughts

Automating translations not only streamlines your workflow but also helps you scale your advertising efforts across multiple markets. By integrating Python, ChatGPT, and Google Ads Editor, you can maintain high-quality, optimized campaigns tailored for international audiences.

Stay tuned for our next post in the series, and don’t forget to subscribe to our channel for more tips on digital marketing automation!


Have questions or need further assistance? Leave a comment below, and we’ll be happy to help you optimize your Google Ads strategy.