# Initialize the Google Ad Manager client and services
def
initialize_gam_client ():
"""Initializes the Google Ad Manager client and services."""
try
:
client = ad_manager.AdManagerClient.LoadFromStorage ()
return
{
"client"
:
client ,
"report_service"
:
client.GetService (
"ReportService"
,
version= "v202505"
),
"network_service"
:
client.GetService (
"NetworkService"
),
}
except
Exception as
e :
print
(
f"Error initializing GAM client:
{e} "
)
raise
# Set up the GAM client instance
gam = initialize_gam_client ()
client = gam [
"client"
]
# Get the main client object for DataDownloader
# Set the start and end dates for the report.
current_date = datetime.now ()
.date ()
# Define dates for Future Sell-Through (Start of Current Month to End of Year)
# Start date is the first day of the current month
start_date_calc = date (
current_date.year ,
current_date.month ,
1
)
# End date is December 31st of the current year
# This ensures the range is exactly 1 year for monthly granularity.
end_date_calc = date (
current_date.year ,
12
,
31
)
start_date_gam = {
'year'
:
start_date_calc.year ,
'month'
:
start_date_calc.month ,
'day'
:
start_date_calc.day
}
end_date_gam = {
'year'
:
end_date_calc.year ,
'month'
:
end_date_calc.month ,
'day'
:
end_date_calc.day
}
# Define the report query as a simple Python dictionary directly.
report_query = {
'dimensions'
:
[
'DATE'
],
'columns'
:
[
'TOTAL_FORECAST_IMPRESSIONS'
],
'dateRangeType'
:
'CUSTOM_DATE'
,
'startDate'
:
start_date_gam ,
'endDate'
:
end_date_gam ,
'reportType'
:
'FUTURE_SELL_THROUGH'
}
The Reponse:
" An unexpected error occurred during report processing: 'reportType'"
Thank you!
Chad