@@ -42,6 +42,21 @@ def main(
4242 """
4343 googleads_service = client .get_service ("GoogleAdsService" )
4444
45+ # Query the asset group to find the associated campaign resource name.
46+ query = f"""
47+ SELECT asset_group.campaign
48+ FROM asset_group
49+ WHERE asset_group.id = { asset_group_id }
50+ """
51+ search_response = googleads_service .search (
52+ customer_id = customer_id , query = query
53+ )
54+ if len (search_response ):
55+ campaign_resource_name = search_response [0 ].asset_group .campaign
56+ else :
57+ print (f"Asset group with ID { asset_group_id } not found." )
58+ sys .exit (1 )
59+
4560 # Temp IDs
4661 ASSET_1_TEMP_ID = "-1"
4762 EXPERIMENT_TEMP_ID = "-2"
@@ -54,7 +69,7 @@ def main(
5469 client ,
5570 customer_id ,
5671 ASSET_1_TEMP_ID ,
57- "Fly to Mars with Interplanetary Cruises !" ,
72+ "Fly to Mars!" ,
5873 )
5974 asset_operation_2 = create_image_asset_operation (
6075 client ,
@@ -76,7 +91,6 @@ def main(
7691 experiment .optimize_assets_experiment .optimize_assets_experiment_subtype = (
7792 client .enums .OptimizeAssetsExperimentSubtypeEnum .COMPARE_ASSETS
7893 )
79- experiment .status = client .enums .ExperimentStatusEnum .SETUP
8094
8195 # 3. Create two ExperimentArm resources.
8296 treatment_assets = [
@@ -87,6 +101,7 @@ def main(
87101 client ,
88102 customer_id ,
89103 EXPERIMENT_TEMP_ID ,
104+ campaign_resource_name ,
90105 asset_group_id ,
91106 treatment_assets ,
92107 )
@@ -189,6 +204,7 @@ def create_arms_operations(
189204 client : GoogleAdsClient ,
190205 customer_id : str ,
191206 experiment_temp_id : str ,
207+ campaign_resource_name : str ,
192208 asset_group_id : str ,
193209 treatment_assets : List [Tuple [str , Any ]],
194210) -> List [MutateOperation ]:
@@ -206,6 +222,7 @@ def create_arms_operations(
206222 control .name = "Base Assets (Control)"
207223 control .control = True
208224 control .traffic_split = 50
225+ control .campaigns .append (campaign_resource_name )
209226
210227 asset_group_info_control = experiment_arm_type .AssetGroupInfo ()
211228 asset_group_info_control .asset_group = googleads_service .asset_group_path (
@@ -223,6 +240,7 @@ def create_arms_operations(
223240 treatment .name = "New Assets (Treatment)"
224241 treatment .control = False
225242 treatment .traffic_split = 50
243+ treatment .campaigns .append (campaign_resource_name )
226244
227245 asset_group_info_treatment = experiment_arm_type .AssetGroupInfo ()
228246 asset_group_info_treatment .asset_group = googleads_service .asset_group_path (
0 commit comments