Google Shopping Merchant Conversions API client library for managing conversion sources and tracking.
82
Utility methods for constructing and parsing Google Cloud resource paths. These helpers ensure correct resource identification and are essential for working with Google Cloud APIs, following the standard resource naming conventions.
Constructs a conversion source resource path from account and conversion source identifiers.
@classmethod
def conversion_source_path(cls, account: str, conversion_source: str) -> str: ...Parameters:
account: The account IDconversion_source: The conversion source IDReturns: Formatted resource path string
Usage Example:
from google.shopping import merchant_conversions_v1
# Construct conversion source path
path = merchant_conversions_v1.ConversionSourcesServiceClient.conversion_source_path(
account="123456789",
conversion_source="abc123"
)
print(path) # accounts/123456789/conversionSources/abc123
# Use in API calls
client = merchant_conversions_v1.ConversionSourcesServiceClient()
request = merchant_conversions_v1.GetConversionSourceRequest(name=path)
response = client.get_conversion_source(request=request)Parses a conversion source resource path into its component parts.
@staticmethod
def parse_conversion_source_path(path: str) -> Dict[str, str]: ...Parameters:
path: The resource path to parseReturns: Dictionary with 'account' and 'conversion_source' keys
Usage Example:
from google.shopping import merchant_conversions_v1
# Parse conversion source path
path = "accounts/123456789/conversionSources/abc123"
parsed = merchant_conversions_v1.ConversionSourcesServiceClient.parse_conversion_source_path(path)
print(parsed) # {'account': '123456789', 'conversion_source': 'abc123'}
# Extract components
account_id = parsed['account']
source_id = parsed['conversion_source']@classmethod
def common_billing_account_path(cls, billing_account: str) -> str: ...
@staticmethod
def parse_common_billing_account_path(path: str) -> Dict[str, str]: ...Usage Example:
from google.shopping import merchant_conversions_v1
# Construct billing account path
path = merchant_conversions_v1.ConversionSourcesServiceClient.common_billing_account_path("123456789")
print(path) # billingAccounts/123456789
# Parse billing account path
parsed = merchant_conversions_v1.ConversionSourcesServiceClient.parse_common_billing_account_path(path)
print(parsed) # {'billing_account': '123456789'}@classmethod
def common_folder_path(cls, folder: str) -> str: ...
@staticmethod
def parse_common_folder_path(path: str) -> Dict[str, str]: ...Usage Example:
from google.shopping import merchant_conversions_v1
# Construct folder path
path = merchant_conversions_v1.ConversionSourcesServiceClient.common_folder_path("987654321")
print(path) # folders/987654321
# Parse folder path
parsed = merchant_conversions_v1.ConversionSourcesServiceClient.parse_common_folder_path(path)
print(parsed) # {'folder': '987654321'}@classmethod
def common_organization_path(cls, organization: str) -> str: ...
@staticmethod
def parse_common_organization_path(path: str) -> Dict[str, str]: ...Usage Example:
from google.shopping import merchant_conversions_v1
# Construct organization path
path = merchant_conversions_v1.ConversionSourcesServiceClient.common_organization_path("456789123")
print(path) # organizations/456789123
# Parse organization path
parsed = merchant_conversions_v1.ConversionSourcesServiceClient.parse_common_organization_path(path)
print(parsed) # {'organization': '456789123'}@classmethod
def common_project_path(cls, project: str) -> str: ...
@staticmethod
def parse_common_project_path(path: str) -> Dict[str, str]: ...Usage Example:
from google.shopping import merchant_conversions_v1
# Construct project path
path = merchant_conversions_v1.ConversionSourcesServiceClient.common_project_path("my-project-id")
print(path) # projects/my-project-id
# Parse project path
parsed = merchant_conversions_v1.ConversionSourcesServiceClient.parse_common_project_path(path)
print(parsed) # {'project': 'my-project-id'}@classmethod
def common_location_path(cls, project: str, location: str) -> str: ...
@staticmethod
def parse_common_location_path(path: str) -> Dict[str, str]: ...Parameters for common_location_path:
project: The project IDlocation: The location/region identifierUsage Example:
from google.shopping import merchant_conversions_v1
# Construct location path
path = merchant_conversions_v1.ConversionSourcesServiceClient.common_location_path(
project="my-project-id",
location="us-central1"
)
print(path) # projects/my-project-id/locations/us-central1
# Parse location path
parsed = merchant_conversions_v1.ConversionSourcesServiceClient.parse_common_location_path(path)
print(parsed) # {'project': 'my-project-id', 'location': 'us-central1'}Resource path helpers include validation and will raise exceptions for invalid inputs:
from google.shopping import merchant_conversions_v1
try:
# Valid path construction
path = merchant_conversions_v1.ConversionSourcesServiceClient.conversion_source_path(
account="123456789",
conversion_source="valid-id"
)
print(f"Valid path: {path}")
# Valid path parsing
parsed = merchant_conversions_v1.ConversionSourcesServiceClient.parse_conversion_source_path(path)
print(f"Parsed: {parsed}")
except ValueError as e:
print(f"Invalid path format: {e}")
except TypeError as e:
print(f"Invalid parameter type: {e}")
try:
# Invalid path parsing
invalid_path = "invalid/path/format"
parsed = merchant_conversions_v1.ConversionSourcesServiceClient.parse_conversion_source_path(invalid_path)
except ValueError as e:
print(f"Failed to parse invalid path: {e}")from google.shopping import merchant_conversions_v1
def manage_conversion_source(account_id: str, source_id: str = None):
client = merchant_conversions_v1.ConversionSourcesServiceClient()
if source_id:
# Work with existing source
path = client.conversion_source_path(account_id, source_id)
request = merchant_conversions_v1.GetConversionSourceRequest(name=path)
source = client.get_conversion_source(request=request)
return source
else:
# List all sources for account
parent = f"accounts/{account_id}"
request = merchant_conversions_v1.ListConversionSourcesRequest(parent=parent)
response = client.list_conversion_sources(request=request)
return response.conversion_sources
# Usage
sources = manage_conversion_source("123456789") # List all
specific_source = manage_conversion_source("123456789", "abc123") # Get specificfrom google.shopping import merchant_conversions_v1
def extract_ids_from_source(conversion_source: merchant_conversions_v1.ConversionSource):
"""Extract account and source IDs from a ConversionSource object."""
client = merchant_conversions_v1.ConversionSourcesServiceClient()
# Parse the resource name
parsed = client.parse_conversion_source_path(conversion_source.name)
return {
'account_id': parsed['account'],
'source_id': parsed['conversion_source'],
'full_path': conversion_source.name
}
# Usage with API response
client = merchant_conversions_v1.ConversionSourcesServiceClient()
request = merchant_conversions_v1.ListConversionSourcesRequest(parent="accounts/123456789")
response = client.list_conversion_sources(request=request)
for source in response.conversion_sources:
ids = extract_ids_from_source(source)
print(f"Account: {ids['account_id']}, Source: {ids['source_id']}")from google.shopping import merchant_conversions_v1
def batch_delete_sources(account_id: str, source_ids: list):
"""Delete multiple conversion sources."""
client = merchant_conversions_v1.ConversionSourcesServiceClient()
results = []
for source_id in source_ids:
try:
# Construct path for each source
path = client.conversion_source_path(account_id, source_id)
request = merchant_conversions_v1.DeleteConversionSourceRequest(name=path)
client.delete_conversion_source(request=request)
results.append({'source_id': source_id, 'status': 'deleted'})
except Exception as e:
results.append({'source_id': source_id, 'status': 'error', 'error': str(e)})
return results
# Usage
results = batch_delete_sources("123456789", ["source1", "source2", "source3"])
for result in results:
print(f"Source {result['source_id']}: {result['status']}")Install with Tessl CLI
npx tessl i tessl/pypi-google-shopping-merchant-conversionsevals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10