Git Product home page Git Product logo

customer-match-upload-script's Introduction

DISCLAIMER: This is not an officially supported Google product.

Customer Match upload script

About

This tool uploads Customer Match lists to Google Ads via API.

Usage

Google Ads setup

Before running the script, you should create a remarketing list in Google Ads. It is recommended to set the membership duration to the N+3, where N is the number of days between script runs. This way, the list will be maintained with only those users that are in the audience file. If a user is removed from the file, it won't be added in the next script run and it will be eventually deleted. Matching process may take time; the +3 is a safeguard period to avoid unwanted temporary removals during this processing time.

Set-up

First, you must obtain the appropriate credentials so that the script can connect to Google Ads API and upload the data. Follow the instructions here to obtain OAuth 2.0 Client IDs for an Installed App. Then, download the client secrets json file to the working directory (this file contains a Client ID and Client secret).

Once you have the file, you must obtain a Refresh token using this script:

python generate_refresh_token.py --client_secrets_path CLIENT_SECRETS_FILE

Where CLIENT_SECRETS_FILE must be substituted with the client secrets file path you downloaded previously.

The script will generate a Refresh token and print it on screen. Make a copy of it as we'll need it later.

Next, get a Developer token from Google Ads by following the instructions here.

Once you have the Client ID, Client secret, Refresh token and Developer token, you must add them to the script config file. In order to do so, edit the file googleads_config.yaml and enter the appropriate values. You'll also need the Google Ads MCC Customer ID, which you can find in Google Ads UI.

Input preparation

Your audience file should be named audience.csv and must be in CSV format. You must specify the fields to upload in the header row. The available fields are:

  • Email
  • Phone
  • FirstName
  • LastName
  • CountryCode
  • ZipCode
  • MobileId
  • UserId
  • List

You can use plain text values and the script will hash them before uploading, or you can hash them yourself (the desired behaviour is controlled with the --hash_required flag in the script).

Currently there are three types of customer lists available:

  • Customers based on email, phone, and/or mailing address uploads (CONTACT_INFO)
  • Customers based on Mobile Device ID uploads (MOBILE_ADVERTISING_ID)
  • Customers based on User ID uploads (CRM_ID)

The type of list to upload is controlled using the list_typeflag (the default value is CONTACT_INFO)

Each type of list only allows certain fields to be uploaded. You need to take that into account while preparing the data. The script will filter those fields depending on the list_type specified, but if the lists already exists and doesn't match the type specified, it will show an error in the upload operation.

These are the fields allowed per type:

  • CONTACT_INFO:
    • Email
    • Phone
    • FirstName
    • LastName
    • CountryCode
    • ZipCode
    • List
  • MOBILE_ADVERTISING_ID:
    • MobileId
    • List
  • CRM_ID:
    • UserId
    • List

Running the script

Once the configuration file is ready, and you have the audience file in audience.csv you can execute the script to upload the data to Google Ads:

python create_and_populate_list.py --customer_id CUSTOMER_ID

Where CUSTOMER_ID represents the Customer ID of the account where the user list will be created.

If your audience file doesn't contain a column for the audience name, you can specify a default audience to which all entries will be added. Here, YOUR_AUDIENCE_NAME will typically be the name of the audience you manually created in Google Ads for the purposes of this script:

python create_and_populate_list.py --customer_id CUSTOMER_ID --audience_name YOUR_AUDIENCE_NAME

If you don't specify any remarketing list in the audience file, the script will create a new audience list with a default name (controlled by the GENERIC_LIST variable in the script) and will add all the users to that one.

You can also specify the list type by using the --list_type flag, and passing one of the allowed values: CONTACT_INFO, MOBILE_ADVERTISING_ID,CRM_ID. The default if not specified is CONTACT_INFO.

The data is not hashed by default. If you need the script to hash the customer data, you can use the --hash_required flag to enable it.

The script has more optional parameters that allow working with custom configuration and audience file paths. For more info on them, run:

python create_and_populate_list.py --help

Checking the results

By default, the script launches the upload jobs, and returns. You can use the --wait flag to wait for the job to finish, but as the upload jobs can take up to 48 hours to finish, waiting is not recommended.

If you don't specify the wait flag, the script will print the job ids in the standard output, and the command you can use to check the job status.

This is an output example:

Offline user data job ID '9999999' with type 'CUSTOMER_MATCH_USER_LIST' has status: RUNNING
To check the status of the job periodically, use the following GAQL query with GoogleAdsService.Search:
        SELECT
          offline_user_data_job.resource_name,
          offline_user_data_job.id,
          offline_user_data_job.status,
          offline_user_data_job.type,
          offline_user_data_job.failure_reason
        FROM offline_user_data_job
        WHERE offline_user_data_job.resource_name =
          'customers/0000000000/offlineUserDataJobs/9999999'
        LIMIT 1
Or you can use the check_job.py script with the following args:

python check_job.py --config_file ./csemcc_config.yaml --customer_id 0000000000 --job_resource_name customers/0000000000/offlineUserDataJobs/9999999 --user_list_resource_name customers/0000000000/userLists/888888888

customer-match-upload-script's People

Contributors

miguelfc avatar mohabfekry avatar pgilmon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

customer-match-upload-script's Issues

Script runs successfully but doesn't upload Audience

Hello,

I have been using this script to upload audience to google-ads, the data gets pulled from Snowflake & is sent to Google-Ads. Until last week it was running fine but from this week onwards I see a strange response stating "Processed 0 lines from file audience.csv".
There is no change to Snowflake database or the table's schema, only the table gets updated with new records on a weekly basis.
It connects to my DB successfully but fails to collect data maybe, Can you please help me understand what might be the issue.

Thanks in Advance !!

Doesn't support Google ads V14

I tried using this on uploading list but it has error and this repo doesn't support version 14. It is only support v10 which is outdated.

Script only passes one identifier per UserData object

It appears that build_offline_user_data_job_operations creates a new OfflineUserDataJobOperation and UserData object for each data_type found in a row. If a single row in the CSV contains entries for multiple data types such as emails and addresses, you should create a single UserData with multiple user_identifiers instead.

So instead of two separate UserData (create) objects for the same member of the list (row in the CSV):

operations {
  create {
    user_identifiers {
      address_info {
        hashed_first_name: "<hashed first name here>"
        hashed_last_name: "<hashed last name here>"
        country_code: "<country code>"
        postal_code: "<postal code>"
      }
    }
  }
  create {
    user_identifiers {
      hashed_email: "<hashed email address here>"
    }
  }
}

You should have one UserData with multiple user_identifiers:

operations {
  create {
    user_identifiers {
      hashed_email: "<hashed email address here>"
    }
    user_identifiers {
      address_info {
        hashed_first_name: "<hashed first name here>"
        hashed_last_name: "<hashed last name here>"
        country_code: "<country code>"
        postal_code: "<postal code>"
      }
    }
  }
}

You still want a separate UserData for each distinct member of the list, but all identifiers for the same member should go under one UserData.

Hope that's helpful!

The client library configuration is missing the required "use_proto_plus" key

I am running Python on windows. So I used pip install google-ads to install the google-ads library. But when I run the create_and_populate_list.py I get the following error:

The client library configuration is missing the required "use_proto_plus" key

So I then copied the file from google-ads.yaml and updated the required parameters. event the client_id, client_secret and refresh_token although these parameters also exist in googleads_config.yaml file. I the edited the create_andpopulate_list.py and added

client = GoogleAdsClient.load_from_storage("location of google-ads.yaml file")

but I still get the same error.

I then added the use_proto_plus: flag in the googleads_config.yaml. Still the same error.

Where must I put the googleads_config.yaml for this to work?

line 278, in load_from_storage config_data = config.load_from_yaml_file(path)
File "C:\config.py", line 69, in validation_wrapper config_dict = func(*args, **kwargs)
File "C:\config.py", line 87, in parser_wrapper config_dict = func(*args, **kwargs)
File "C:\config.py", line 274, in load_from_yaml_file return parse_yaml_document_to_dict(yaml_doc)
File "C:\config.py", line 70, in validation_wrapper validate_dict(config_dict)
File "C:\config.py", line 174, in validate_dict raise ValueError(
ValueError: The client library configuration is missing the required "use_proto_plus" key. Please set this option to either "True" or "False". For more information about this option see the Protobuf Messages guide: https://developers.google.com/google-ads/api/docs/client-libs/python/protobuf-messages

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.