// [END add_performance_max_retail_campaign_7]

        // [START add_performance_max_retail_campaign_8]
        /// <summary>
        /// Creates a list of MutateOperations that create a new linked image asset.
        /// </summary>
        /// <param name="assetGroupResourceName">The resource name of the asset group to be
        /// created.</param>
        /// <param name="assetResourceName">The resource name of the text asset to be
        /// created.</param>
        /// <param name="url">The url of the image to be retrieved and put into an asset.</param>
        /// <param name="fieldType">The field type of the asset to be created.</param>
        /// <param name="assetName">The asset name.</param>
        /// <param name="config">The Google Ads config.</param>
        /// <returns>A list of MutateOperations that create a new linked image asset.</returns>
        private List <MutateOperation> CreateAndLinkImageAsset(
            string assetGroupResourceName,
            string assetResourceName,
            string url,
            AssetFieldType fieldType,
            string assetName,
            GoogleAdsConfig config)
        {
            List <MutateOperation> operations = new List <MutateOperation>();

            // Create the Image Asset.
            operations.Add(
                new MutateOperation()
            {
                AssetOperation = new AssetOperation()
                {
                    Create = new Asset()
                    {
                        ResourceName = assetResourceName,
                        ImageAsset   = new ImageAsset()
                        {
                            Data =
                                ByteString.CopyFrom(
                                    MediaUtilities.GetAssetDataFromUrl(url, config)
                                    )
                        },
                        // Provide a unique friendly name to identify your asset.
                        // When there is an existing image asset with the same content but a
                        // different name, the new name will be dropped silently.
                        Name = assetName
                    }
                }
            }
                );

            // Create an AssetGroupAsset to link the Asset to the AssetGroup.
            operations.Add(
                new MutateOperation()
            {
                AssetGroupAssetOperation = new AssetGroupAssetOperation()
                {
                    Create = new AssetGroupAsset()
                    {
                        FieldType  = fieldType,
                        AssetGroup = assetGroupResourceName,
                        Asset      = assetResourceName
                    }
                }
            }
                );

            return(operations);
        }
Пример #2
0
        // [END add_performance_max_campaign_6]

        // [START add_performance_max_campaign_7]
        /// <summary>
        /// Creates a list of MutateOperations that create a new linked text asset.
        /// </summary>
        /// <param name="assetGroupResourceName">The resource name of the asset group to be
        /// created.</param>
        /// <param name="assetResourceName">The resource name of the text asset to be
        /// created.</param>
        /// <param name="text">The text of the asset to be created.</param>
        /// <param name="fieldType">The field type of the asset to be created.</param>
        /// <returns>A list of MutateOperations that create the new linked text asset.</returns>
        private List <MutateOperation> CreateAndLinkTextAsset(
            string assetGroupResourceName,
            string assetResourceName,
            string text,
            AssetFieldType fieldType)
        {
            List <MutateOperation> operations = new List <MutateOperation>();

            // Create the Text Asset.
            operations.Add(
                new MutateOperation()
            {
                AssetOperation = new AssetOperation()
                {
                    Create = new Asset()
                    {
                        ResourceName = assetResourceName,
                        TextAsset    = new TextAsset()
                        {
                            Text = text
                        }
                    }
                }
            }
                );

            // Create an AssetGroupAsset to link the Asset to the AssetGroup.
            operations.Add(
                new MutateOperation()
            {
                AssetGroupAssetOperation = new AssetGroupAssetOperation()
                {
                    Create = new AssetGroupAsset()
                    {
                        FieldType  = fieldType,
                        AssetGroup = assetGroupResourceName,
                        Asset      = assetResourceName
                    }
                }
            }
                );

            return(operations);
        }
Пример #3
0
 public static string AdGroupAsset(long customerId, long adGroupId, long assetId,
                                   AssetFieldType fieldType)
 {
     return($"customers/{customerId}/adGroupAssets/{adGroupId}~{assetId}~" +
            $"{ProtobufUtilities.GetOriginalEnumFieldName(fieldType)}");
 }
Пример #4
0
 public static string AssetFieldTypeView(long customerId, AssetFieldType fieldType)
 {
     return($"customers/{customerId}/assetFieldTypeViews/" +
            $"{ProtobufUtilities.GetOriginalEnumFieldName(fieldType)}");
 }