Ejemplo n.º 1
0
        /// <summary>
        /// Creates a campaign feed, which tells Google Ads which campaigns to use the provided
        /// data with.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The customer ID for which the call is made.</param>
        /// <param name="campaignId">The campaign to receive the feed.</param>
        /// <param name="feed">The feed to connect to the campaign.</param>
        private void CreateCampaignFeed(GoogleAdsClient client, long customerId, long campaignId,
                                        Feed feed)
        {
            CampaignFeedServiceClient campaignFeedServiceClient =
                client.GetService(Services.V4.CampaignFeedService);

            // Fetch the Feed Item IDs and collapse them into a single comma-separated string.
            List <long>  feedItemIds           = feed.Attributes.Select(attr => attr.Id.Value).ToList();
            string       aggregatedFeedItemIds = string.Join(",", feedItemIds);
            CampaignFeed campaignFeed          = new CampaignFeed()
            {
                Feed             = feed.ResourceName,
                Campaign         = ResourceNames.Campaign(customerId, campaignId),
                MatchingFunction = new MatchingFunction()
                {
                    FunctionString = $"AND(IN(FEED_ITEM_ID,{{ {aggregatedFeedItemIds} }})," +
                                     "EQUALS(CONTEXT.DEVICE,'Mobile'))"
                }
            };

            campaignFeed.PlaceholderTypes.Add(PlaceholderTypeEnum.Types.PlaceholderType.Sitelink);

            CampaignFeedOperation operation = new CampaignFeedOperation()
            {
                Create = campaignFeed
            };

            MutateCampaignFeedsResponse response = campaignFeedServiceClient.MutateCampaignFeeds(
                customerId.ToString(), new[] { operation });

            Console.WriteLine($"Created campaign feed '{response.Results.First().ResourceName}'");
        }
Ejemplo n.º 2
0
 /// <summary>Snippet for MutateCampaignFeeds</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void MutateCampaignFeeds()
 {
     // Create client
     CampaignFeedServiceClient campaignFeedServiceClient = CampaignFeedServiceClient.Create();
     // Initialize request argument(s)
     string customerId = "";
     IEnumerable <CampaignFeedOperation> operations = new CampaignFeedOperation[]
     {
         new CampaignFeedOperation(),
     };
     // Make the request
     MutateCampaignFeedsResponse response = campaignFeedServiceClient.MutateCampaignFeeds(customerId, operations);
 }
 /// <summary>Snippet for MutateCampaignFeeds</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void MutateCampaignFeedsRequestObject()
 {
     // Create client
     CampaignFeedServiceClient campaignFeedServiceClient = CampaignFeedServiceClient.Create();
     // Initialize request argument(s)
     MutateCampaignFeedsRequest request = new MutateCampaignFeedsRequest
     {
         CustomerId = "",
         Operations =
         {
             new CampaignFeedOperation(),
         },
         PartialFailure = false,
         ValidateOnly   = false,
     };
     // Make the request
     MutateCampaignFeedsResponse response = campaignFeedServiceClient.MutateCampaignFeeds(request);
 }
 /// <summary>Snippet for MutateCampaignFeeds</summary>
 public void MutateCampaignFeedsRequestObject()
 {
     // Snippet: MutateCampaignFeeds(MutateCampaignFeedsRequest, CallSettings)
     // Create client
     CampaignFeedServiceClient campaignFeedServiceClient = CampaignFeedServiceClient.Create();
     // Initialize request argument(s)
     MutateCampaignFeedsRequest request = new MutateCampaignFeedsRequest
     {
         CustomerId = "",
         Operations =
         {
             new CampaignFeedOperation(),
         },
         PartialFailure      = false,
         ValidateOnly        = false,
         ResponseContentType = ResponseContentTypeEnum.Types.ResponseContentType.Unspecified,
     };
     // Make the request
     MutateCampaignFeedsResponse response = campaignFeedServiceClient.MutateCampaignFeeds(request);
     // End snippet
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates the campaign feed.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The customer ID for which the call is made.</param>
        /// <param name="campaignId">The campaign ID for which the affiliate location extensions
        /// are added.</param>
        /// <param name="feedMapping">The affliate location extension feedmapping for
        /// <paramref name="feedResourceName"/></param>
        /// <param name="feedResourceName">The feed resource name.</param>
        /// <param name="chainId">The retail chain ID.</param>
        private static void CreateCampaignFeed(GoogleAdsClient client, long customerId,
                                               long campaignId, FeedMapping feedMapping, string feedResourceName, long chainId)
        {
            // Get the CampaignFeedService.
            CampaignFeedServiceClient campaignFeedService = client.GetService(
                Services.V5.CampaignFeedService);

            long   attributeIdForChainId = GetAttributeIdForChainId(feedMapping);
            string feedId = FeedName.Parse(feedResourceName).FeedId;

            string matchingFunction =
                $"IN(FeedAttribute[{feedId}, {attributeIdForChainId}], {chainId})";
            // Adds a CampaignFeed that associates the feed with this campaign for
            // the AFFILIATE_LOCATION placeholder type.
            CampaignFeed campaignFeed = new CampaignFeed()
            {
                Feed             = feedResourceName,
                PlaceholderTypes = { PlaceholderType.AffiliateLocation },
                MatchingFunction = new MatchingFunction()
                {
                    FunctionString = matchingFunction
                },
                Campaign = ResourceNames.Campaign(customerId, campaignId),
            };

            CampaignFeedOperation operation = new CampaignFeedOperation()
            {
                Create = campaignFeed
            };

            MutateCampaignFeedsResponse campaignFeedsResponse =
                campaignFeedService.MutateCampaignFeeds(
                    customerId.ToString(), new[] { operation });

            // Displays the result.
            string addedCampaignFeed = campaignFeedsResponse.Results[0].ResourceName;

            Console.WriteLine($"Campaign feed created with resource name: {addedCampaignFeed}.");
            return;
        }