You must enable conversion tracking in your Google Ads conversion account in order to record conversions. This guide provides details on how to confirm whether conversion tracking is enabled, enable it if it isn't enabled already, and retrieve information about existing conversion actions.
Most conversion actions also require additional steps on your part to track them. For more information on the various conversion action types and their requirements, see the Create conversion actions guide.
Set up your website to track conversions
If you're starting your offline conversion import integration, the first step is to follow the steps in the Configure the Google tag for enhanced conversions for leads guide to configure your website to track enhanced conversions for leads. You can also use Google Tag Manager to configure your website by following the steps in the Configure Google Tag Manager for enhanced conversions for leads guide.
Enable conversion tracking in your Google Ads conversion account
Retrieve information about your conversion tracking setup
You can check your account's conversion tracking setup and confirm conversion
tracking is enabled by querying the Customer
resource
for the ConversionTrackingSetting
.
Issue the following query with
GoogleAdsService.SearchStream
:
SELECT
customer.conversion_tracking_setting.google_ads_conversion_customer,
customer.conversion_tracking_setting.conversion_tracking_status,
customer.conversion_tracking_setting.conversion_tracking_id,
customer.conversion_tracking_setting.cross_account_conversion_tracking_id
FROM customer
The google_ads_conversion_customer
field indicates the Google Ads account that
creates and manages conversions for this customer. For customers using
cross-account conversion tracking,
this is the ID of a manager account. The Google Ads conversion customer ID should be
given as the customer_id
in Google Ads API requests to create and manage conversions.
Note that this field is populated even if conversion tracking is not enabled.
The
conversion_tracking_status
field indicates whether conversion tracking is enabled and whether the account
is using cross-account conversion tracking.
Create a conversion action under the Google Ads conversion customer
If the conversion_tracking_status
value is NOT_CONVERSION_TRACKED
,
conversion tracking is not enabled for the account. Enable conversion tracking
by creating at least one ConversionAction
in
the Google Ads conversion account, like in the following example. Alternatively, you
can create a conversion action in the UI by following the instructions in the
Help Center for the
conversion type you want to enable.
Note that enhanced conversions are enabled automatically when sent through the Google Ads API, but they can be disabled through the Google Ads UI.
Code example
Java
private void runExample(GoogleAdsClient googleAdsClient, long customerId) { // Creates a ConversionAction. ConversionAction conversionAction = ConversionAction.newBuilder() // Note that conversion action names must be unique. If a conversion action already // exists with the specified conversion_action_name the create operation will fail with // a ConversionActionError.DUPLICATE_NAME error. .setName("Earth to Mars Cruises Conversion #" + getPrintableDateTime()) .setCategory(ConversionActionCategory.DEFAULT) .setType(ConversionActionType.WEBPAGE) .setStatus(ConversionActionStatus.ENABLED) .setViewThroughLookbackWindowDays(15L) .setValueSettings( ValueSettings.newBuilder() .setDefaultValue(23.41) .setAlwaysUseDefaultValue(true) .build()) .build(); // Creates the operation. ConversionActionOperation operation = ConversionActionOperation.newBuilder().setCreate(conversionAction).build(); try (ConversionActionServiceClient conversionActionServiceClient = googleAdsClient.getLatestVersion().createConversionActionServiceClient()) { MutateConversionActionsResponse response = conversionActionServiceClient.mutateConversionActions( Long.toString(customerId), Collections.singletonList(operation)); System.out.printf("Added %d conversion actions:%n", response.getResultsCount()); for (MutateConversionActionResult result : response.getResultsList()) { System.out.printf( "New conversion action added with resource name: '%s'%n", result.getResourceName()); } } }
C#
public void Run(GoogleAdsClient client, long customerId) { // Get the ConversionActionService. ConversionActionServiceClient conversionActionService = client.GetService(Services.V19.ConversionActionService); // Note that conversion action names must be unique. // If a conversion action already exists with the specified name the create operation // will fail with a ConversionAction.DUPLICATE_NAME error. string ConversionActionName = "Earth to Mars Cruises Conversion #" + ExampleUtilities.GetRandomString(); // Add a conversion action. ConversionAction conversionAction = new ConversionAction() { Name = ConversionActionName, Category = ConversionActionCategory.Default, Type = ConversionActionType.Webpage, Status = ConversionActionStatus.Enabled, ViewThroughLookbackWindowDays = 15, ValueSettings = new ConversionAction.Types.ValueSettings() { DefaultValue = 23.41, AlwaysUseDefaultValue = true } }; // Create the operation. ConversionActionOperation operation = new ConversionActionOperation() { Create = conversionAction }; try { // Create the conversion action. MutateConversionActionsResponse response = conversionActionService.MutateConversionActions(customerId.ToString(), new ConversionActionOperation[] { operation }); // Display the results. foreach (MutateConversionActionResult newConversionAction in response.Results) { Console.WriteLine($"New conversion action with resource name = " + $"'{newConversionAction.ResourceName}' was added."); } } catch (GoogleAdsException e) { Console.WriteLine("Failure:"); Console.WriteLine($"Message: {e.Message}"); Console.WriteLine($"Failure: {e.Failure}"); Console.WriteLine($"Request ID: {e.RequestId}"); throw; } }
PHP
public static function runExample(GoogleAdsClient $googleAdsClient, int $customerId) { // Creates a conversion action. $conversionAction = new ConversionAction([ // Note that conversion action names must be unique. // If a conversion action already exists with the specified conversion_action_name // the create operation will fail with a ConversionActionError.DUPLICATE_NAME error. 'name' => 'Earth to Mars Cruises Conversion #' . Helper::getPrintableDatetime(), 'category' => ConversionActionCategory::PBDEFAULT, 'type' => ConversionActionType::WEBPAGE, 'status' => ConversionActionStatus::ENABLED, 'view_through_lookback_window_days' => 15, 'value_settings' => new ValueSettings([ 'default_value' => 23.41, 'always_use_default_value' => true ]) ]); // Creates a conversion action operation. $conversionActionOperation = new ConversionActionOperation(); $conversionActionOperation->setCreate($conversionAction); // Issues a mutate request to add the conversion action. $conversionActionServiceClient = $googleAdsClient->getConversionActionServiceClient(); $response = $conversionActionServiceClient->mutateConversionActions( MutateConversionActionsRequest::build($customerId, [$conversionActionOperation]) ); printf("Added %d conversion actions:%s", $response->getResults()->count(), PHP_EOL); foreach ($response->getResults() as $addedConversionAction) { /** @var ConversionAction $addedConversionAction */ printf( "New conversion action added with resource name: '%s'%s", $addedConversionAction->getResourceName(), PHP_EOL ); } }
Python
def main(client, customer_id): conversion_action_service = client.get_service("ConversionActionService") # Create the operation. conversion_action_operation = client.get_type("ConversionActionOperation") # Create conversion action. conversion_action = conversion_action_operation.create # Note that conversion action names must be unique. If a conversion action # already exists with the specified conversion_action_name, the create # operation will fail with a ConversionActionError.DUPLICATE_NAME error. conversion_action.name = f"Earth to Mars Cruises Conversion {uuid.uuid4()}" conversion_action.type_ = ( client.enums.ConversionActionTypeEnum.UPLOAD_CLICKS ) conversion_action.category = ( client.enums.ConversionActionCategoryEnum.DEFAULT ) conversion_action.status = client.enums.ConversionActionStatusEnum.ENABLED conversion_action.view_through_lookback_window_days = 15 # Create a value settings object. value_settings = conversion_action.value_settings value_settings.default_value = 15.0 value_settings.always_use_default_value = True # Add the conversion action. conversion_action_response = ( conversion_action_service.mutate_conversion_actions( customer_id=customer_id, operations=[conversion_action_operation], ) ) print( "Created conversion action " f'"{conversion_action_response.results[0].resource_name}".' )
Ruby
def add_conversion_action(customer_id) # GoogleAdsClient will read a config file from # ENV['HOME']/google_ads_config.rb when called without parameters client = Google::Ads::GoogleAds::GoogleAdsClient.new # Add a conversion action. conversion_action = client.resource.conversion_action do |ca| ca.name = "Earth to Mars Cruises Conversion #{(Time.new.to_f * 100).to_i}" ca.type = :UPLOAD_CLICKS ca.category = :DEFAULT ca.status = :ENABLED ca.view_through_lookback_window_days = 15 # Create a value settings object. ca.value_settings = client.resource.value_settings do |vs| vs.default_value = 15 vs.always_use_default_value = true end end # Create the operation. conversion_action_operation = client.operation.create_resource.conversion_action(conversion_action) # Add the ad group ad. response = client.service.conversion_action.mutate_conversion_actions( customer_id: customer_id, operations: [conversion_action_operation], ) puts "New conversion action with resource name = #{response.results.first.resource_name}." end
Perl
sub add_conversion_action { my ($api_client, $customer_id) = @_; # Note that conversion action names must be unique. # If a conversion action already exists with the specified conversion_action_name, # the create operation fails with error ConversionActionError.DUPLICATE_NAME. my $conversion_action_name = "Earth to Mars Cruises Conversion #" . uniqid(); # Create a conversion action. my $conversion_action = Google::Ads::GoogleAds::V19::Resources::ConversionAction->new({ name => $conversion_action_name, category => DEFAULT, type => WEBPAGE, status => ENABLED, viewThroughLookbackWindowDays => 15, valueSettings => Google::Ads::GoogleAds::V19::Resources::ValueSettings->new({ defaultValue => 23.41, alwaysUseDefaultValue => "true" })}); # Create a conversion action operation. my $conversion_action_operation = Google::Ads::GoogleAds::V19::Services::ConversionActionService::ConversionActionOperation ->new({create => $conversion_action}); # Add the conversion action. my $conversion_actions_response = $api_client->ConversionActionService()->mutate({ customerId => $customer_id, operations => [$conversion_action_operation]}); printf "New conversion action added with resource name: '%s'.\n", $conversion_actions_response->{results}[0]{resourceName}; return 1; }
Make sure the conversion_action_type
is set to the correct
ConversionActionType
value.
For more guidance on creating conversion actions in the Google Ads API, see Create Conversion Actions.
Retrieve an existing conversion action
You can retrieve details for an existing conversion action by issuing the
following query. Make sure the customer ID in the request is set to the Google Ads
conversion customer you identified above, and the conversion action type is set
to the correct
ConversionActionType
value.
SELECT
conversion_action.resource_name,
conversion_action.name,
conversion_action.status
FROM conversion_action
WHERE conversion_action.type = 'INSERT_CONVERSION_ACTION_TYPE'
Cross-account conversion tracking
If you're using cross-account conversion
tracking, the
ConversionActionService
returns the
following conversion actions:
- All conversion actions defined by the manager account used by the account for cross-account conversion tracking
- All conversion actions on which the customer has accrued stats, including system-defined actions, and actions owned by the manager even if that manager unlinks subsequently
- All actions the customer has defined in their own account
- Analytics conversions created in linked Google Analytics properties.
This includes actions for Analytics conversions not imported into Google Ads,
which have a status of
HIDDEN
.
Starting in v19.1
, you can use the
Google Ads API to opt into cross-conversion tracking when creating client accounts.
When creating a new Customer
, set the
conversion_tracking_setting.google_ads_conversion_customer
to the resource name of the manager account that should manage conversion
actions on behalf of the client account. This manager account must also be the
account that issues the create
request for the new client account.
To opt into cross-conversion tracking for existing client accounts, you will need to use the Google Ads UI following these instructions.
Create conversion actions
To measure conversions, set up a
ConversionAction
for the
type
of
conversion action you want to track. For example, an online purchase and a phone
call require different conversion actions.
The best way to set up new conversion actions in the API is to use the
Add Conversion Action code example below. The sample handles
all the background authentication tasks for you, and walks you through creating
a ConversionAction
.
Most conversion actions also require additional steps on your part to track them. For example, to track conversions on your website, you must add a code snippet called a tag to the conversion page on your website. For detailed requirements of other conversion action types, see our Help Center article.
Code example
The following code example walks you through the process of creating a new
conversion action. Specifically, it creates a conversion action with the
type
set to
UPLOAD_CLICKS
.
This is the same Google Ads UI flow as creating a new conversion action using
Import > Manual import using API or uploads > Track conversions from
clicks. It also sets the category
to DEFAULT
.
The following default settings apply:
The Google Ads API sets the
primary_for_goal
field automatically, but you can set this field explicitly to control how a conversion action impacts reporting and bidding in your account when combined with your conversion goals.The Google Ads API sets the
counting_type
automatically toMANY_PER_CLICK
See About conversion counting options for more details.The Google Ads API sets the attribution model to be Data driven by setting the
attribution_model_settings
field to theGOOGLE_SEARCH_ATTRIBUTION_DATA_DRIVEN
value ofAttributionModel
. See this Help Center article to learn more about attribution models.
Java
private void runExample(GoogleAdsClient googleAdsClient, long customerId) { // Creates a ConversionAction. ConversionAction conversionAction = ConversionAction.newBuilder() // Note that conversion action names must be unique. If a conversion action already // exists with the specified conversion_action_name the create operation will fail with // a ConversionActionError.DUPLICATE_NAME error. .setName("Earth to Mars Cruises Conversion #" + getPrintableDateTime()) .setCategory(ConversionActionCategory.DEFAULT) .setType(ConversionActionType.WEBPAGE) .setStatus(ConversionActionStatus.ENABLED) .setViewThroughLookbackWindowDays(15L) .setValueSettings( ValueSettings.newBuilder() .setDefaultValue(23.41) .setAlwaysUseDefaultValue(true) .build()) .build(); // Creates the operation. ConversionActionOperation operation = ConversionActionOperation.newBuilder().setCreate(conversionAction).build(); try (ConversionActionServiceClient conversionActionServiceClient = googleAdsClient.getLatestVersion().createConversionActionServiceClient()) { MutateConversionActionsResponse response = conversionActionServiceClient.mutateConversionActions( Long.toString(customerId), Collections.singletonList(operation)); System.out.printf("Added %d conversion actions:%n", response.getResultsCount()); for (MutateConversionActionResult result : response.getResultsList()) { System.out.printf( "New conversion action added with resource name: '%s'%n", result.getResourceName()); } } }
C#
public void Run(GoogleAdsClient client, long customerId) { // Get the ConversionActionService. ConversionActionServiceClient conversionActionService = client.GetService(Services.V19.ConversionActionService); // Note that conversion action names must be unique. // If a conversion action already exists with the specified name the create operation // will fail with a ConversionAction.DUPLICATE_NAME error. string ConversionActionName = "Earth to Mars Cruises Conversion #" + ExampleUtilities.GetRandomString(); // Add a conversion action. ConversionAction conversionAction = new ConversionAction() { Name = ConversionActionName, Category = ConversionActionCategory.Default, Type = ConversionActionType.Webpage, Status = ConversionActionStatus.Enabled, ViewThroughLookbackWindowDays = 15, ValueSettings = new ConversionAction.Types.ValueSettings() { DefaultValue = 23.41, AlwaysUseDefaultValue = true } }; // Create the operation. ConversionActionOperation operation = new ConversionActionOperation() { Create = conversionAction }; try { // Create the conversion action. MutateConversionActionsResponse response = conversionActionService.MutateConversionActions(customerId.ToString(), new ConversionActionOperation[] { operation }); // Display the results. foreach (MutateConversionActionResult newConversionAction in response.Results) { Console.WriteLine($"New conversion action with resource name = " + $"'{newConversionAction.ResourceName}' was added."); } } catch (GoogleAdsException e) { Console.WriteLine("Failure:"); Console.WriteLine($"Message: {e.Message}"); Console.WriteLine($"Failure: {e.Failure}"); Console.WriteLine($"Request ID: {e.RequestId}"); throw; } }
PHP
public static function runExample(GoogleAdsClient $googleAdsClient, int $customerId) { // Creates a conversion action. $conversionAction = new ConversionAction([ // Note that conversion action names must be unique. // If a conversion action already exists with the specified conversion_action_name // the create operation will fail with a ConversionActionError.DUPLICATE_NAME error. 'name' => 'Earth to Mars Cruises Conversion #' . Helper::getPrintableDatetime(), 'category' => ConversionActionCategory::PBDEFAULT, 'type' => ConversionActionType::WEBPAGE, 'status' => ConversionActionStatus::ENABLED, 'view_through_lookback_window_days' => 15, 'value_settings' => new ValueSettings([ 'default_value' => 23.41, 'always_use_default_value' => true ]) ]); // Creates a conversion action operation. $conversionActionOperation = new ConversionActionOperation(); $conversionActionOperation->setCreate($conversionAction); // Issues a mutate request to add the conversion action. $conversionActionServiceClient = $googleAdsClient->getConversionActionServiceClient(); $response = $conversionActionServiceClient->mutateConversionActions( MutateConversionActionsRequest::build($customerId, [$conversionActionOperation]) ); printf("Added %d conversion actions:%s", $response->getResults()->count(), PHP_EOL); foreach ($response->getResults() as $addedConversionAction) { /** @var ConversionAction $addedConversionAction */ printf( "New conversion action added with resource name: '%s'%s", $addedConversionAction->getResourceName(), PHP_EOL ); } }
Python
def main(client, customer_id): conversion_action_service = client.get_service("ConversionActionService") # Create the operation. conversion_action_operation = client.get_type("ConversionActionOperation") # Create conversion action. conversion_action = conversion_action_operation.create # Note that conversion action names must be unique. If a conversion action # already exists with the specified conversion_action_name, the create # operation will fail with a ConversionActionError.DUPLICATE_NAME error. conversion_action.name = f"Earth to Mars Cruises Conversion {uuid.uuid4()}" conversion_action.type_ = ( client.enums.ConversionActionTypeEnum.UPLOAD_CLICKS ) conversion_action.category = ( client.enums.ConversionActionCategoryEnum.DEFAULT ) conversion_action.status = client.enums.ConversionActionStatusEnum.ENABLED conversion_action.view_through_lookback_window_days = 15 # Create a value settings object. value_settings = conversion_action.value_settings value_settings.default_value = 15.0 value_settings.always_use_default_value = True # Add the conversion action. conversion_action_response = ( conversion_action_service.mutate_conversion_actions( customer_id=customer_id, operations=[conversion_action_operation], ) ) print( "Created conversion action " f'"{conversion_action_response.results[0].resource_name}".' )
Ruby
def add_conversion_action(customer_id) # GoogleAdsClient will read a config file from # ENV['HOME']/google_ads_config.rb when called without parameters client = Google::Ads::GoogleAds::GoogleAdsClient.new # Add a conversion action. conversion_action = client.resource.conversion_action do |ca| ca.name = "Earth to Mars Cruises Conversion #{(Time.new.to_f * 100).to_i}" ca.type = :UPLOAD_CLICKS ca.category = :DEFAULT ca.status = :ENABLED ca.view_through_lookback_window_days = 15 # Create a value settings object. ca.value_settings = client.resource.value_settings do |vs| vs.default_value = 15 vs.always_use_default_value = true end end # Create the operation. conversion_action_operation = client.operation.create_resource.conversion_action(conversion_action) # Add the ad group ad. response = client.service.conversion_action.mutate_conversion_actions( customer_id: customer_id, operations: [conversion_action_operation], ) puts "New conversion action with resource name = #{response.results.first.resource_name}." end
Perl
sub add_conversion_action { my ($api_client, $customer_id) = @_; # Note that conversion action names must be unique. # If a conversion action already exists with the specified conversion_action_name, # the create operation fails with error ConversionActionError.DUPLICATE_NAME. my $conversion_action_name = "Earth to Mars Cruises Conversion #" . uniqid(); # Create a conversion action. my $conversion_action = Google::Ads::GoogleAds::V19::Resources::ConversionAction->new({ name => $conversion_action_name, category => DEFAULT, type => WEBPAGE, status => ENABLED, viewThroughLookbackWindowDays => 15, valueSettings => Google::Ads::GoogleAds::V19::Resources::ValueSettings->new({ defaultValue => 23.41, alwaysUseDefaultValue => "true" })}); # Create a conversion action operation. my $conversion_action_operation = Google::Ads::GoogleAds::V19::Services::ConversionActionService::ConversionActionOperation ->new({create => $conversion_action}); # Add the conversion action. my $conversion_actions_response = $api_client->ConversionActionService()->mutate({ customerId => $customer_id, operations => [$conversion_action_operation]}); printf "New conversion action added with resource name: '%s'.\n", $conversion_actions_response->{results}[0]{resourceName}; return 1; }
This example can also be found in the Remarketing folder of your client library and in the code examples collection: Add Conversion Action code example.
Validations
Google Ads and the Google Ads API support a wide variety of conversion actions, so some
validation rules vary based on the type
of action.
By far the most common error when creating a conversion action is
DUPLICATE_NAME
.
Make sure you are using a unique name for each conversion action.
Here are some tips on setting the ConversionAction
fields:
- All enum fields
- Attempting to set any enum field to
UNKNOWN
results in aRequestError.INVALID_ENUM_VALUE
error. app_id
- The
app_id
attribute is immutable and can only be set when creating a new app conversion. attribution_model_settings
- Setting this to a deprecated
option
results in a
CANNOT_SET_RULE_BASED_ATTRIBUTION_MODELS
error. Google Ads only supportsGOOGLE_ADS_LAST_CLICK
andGOOGLE_SEARCH_ATTRIBUTION_DATA_DRIVEN
. click_through_lookback_window_days
Setting this attribute to a value outside of the allowed range results in a
RangeError.TOO_LOW
orRangeError.TOO_HIGH
error.This attribute must be in the range
[1,60]
for anAD_CALL
orWEBSITE_CALL
conversion action. For most other conversion actions, the allowed range is[1,30]
.include_in_conversions_metric
Setting this value in a
create
orupdate
operation fails with aFieldError.IMMUTABLE_FIELD
error. Instead, setprimary_for_goal
as described in the Conversion goals guide.phone_call_duration_seconds
Attempting to set this attribute on a conversion action that isn't for calls results in a
FieldError.VALUE_MUST_BE_UNSET
error.type
The
type
attribute is immutable and can only be set when creating a new conversion.Updating a conversion action with
type
equal toUNKNOWN
results in aMutateError.MUTATE_NOT_ALLOWED
error.value_settings
The
value_settings
for aWEBSITE_CALL
orAD_CALL
conversion action must havealways_use_default_value
set totrue
. Specifying a value offalse
when creating or updating this value results in anINVALID_VALUE
error.view_through_lookback_window_days
Setting this attribute to a value outside of the allowed range results in a
RangeError.TOO_LOW
orRangeError.TOO_HIGH
error. For most conversion actions, the allowed range is[1,30]
.This attribute cannot be set on
AD_CALL
orWEBSITE_CALL
conversion actions. Specifying a value results in aVALUE_MUST_BE_UNSET
error.