/// <summary> /// Create a campaign group. /// </summary> /// <param name="user">The AdWords user.</param> /// <returns>The campaign group.</returns> private static CampaignGroup CreateCampaignGroup(AdWordsUser user) { using (CampaignGroupService campaignGroupService = (CampaignGroupService)user.GetService(AdWordsService.v201806.CampaignGroupService)) { // Create the campaign group. CampaignGroup campaignGroup = new CampaignGroup { name = "Mars campaign group - " + ExampleUtilities.GetShortRandomString() }; // Create the operation. CampaignGroupOperation operation = new CampaignGroupOperation { operand = campaignGroup, @operator = Operator.ADD }; try { CampaignGroupReturnValue retval = campaignGroupService.mutate( new CampaignGroupOperation[] { operation }); // Display the results. CampaignGroup newCampaignGroup = retval.value[0]; Console.WriteLine("Campaign group with ID = '{0}' and name = '{1}' was created.", newCampaignGroup.id, newCampaignGroup.name); return(newCampaignGroup); } catch (Exception e) { throw new System.ApplicationException("Failed to add campaign group.", e); } } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="campaignId1">Id of the campaign to be added to the campaign group.</param> /// <param name="campaignId2">Id of the campaign to be added to the campaign group.</param> public void Run(AdWordsUser user, long campaignId1, long campaignId2) { CampaignGroup campaignGroup = CreateCampaignGroup(user); AddCampaignsToGroup(user, campaignGroup.id, new long[] { campaignId1, campaignId2 }); CreatePerformanceTarget(user, campaignGroup.id); Console.WriteLine("Campaign group and its performance target were setup successfully."); }
private CampaignGroup MapProperties(CampaignGroupVm p) { CampaignGroup baseObj = new CampaignGroup(); baseObj.Id = p.Id.GetInt(); baseObj.Title = p.Title.GetString(); baseObj.Details = p.Details.GetString(); baseObj.SchoolYearId = p.SchoolYearId.GetInt(); baseObj.CreatedById = p.CreatedById.GetInt(); baseObj.CreatedOn = p.CreatedOn.GetDateTime(); baseObj.ModifiedById = p.ModifiedById.GetInt(); baseObj.ModifiedOn = p.ModifiedOn.GetNullableDateTime(); return(baseObj); }
public void GetCampaignGroup2() { Mock <CampaignGroupService.CampaignGroupServiceClient> mockGrpcClient = new Mock <CampaignGroupService.CampaignGroupServiceClient>(MockBehavior.Strict); GetCampaignGroupRequest request = new GetCampaignGroupRequest { ResourceName = new CampaignGroupName("[CUSTOMER]", "[CAMPAIGN_GROUP]").ToString(), }; CampaignGroup expectedResponse = new CampaignGroup { ResourceName = "resourceName2625949903", }; mockGrpcClient.Setup(x => x.GetCampaignGroup(request, It.IsAny <CallOptions>())) .Returns(expectedResponse); CampaignGroupServiceClient client = new CampaignGroupServiceClientImpl(mockGrpcClient.Object, null); CampaignGroup response = client.GetCampaignGroup(request); Assert.AreEqual(expectedResponse, response); mockGrpcClient.VerifyAll(); }
public async Task GetCampaignGroupAsync2() { Mock <CampaignGroupService.CampaignGroupServiceClient> mockGrpcClient = new Mock <CampaignGroupService.CampaignGroupServiceClient>(MockBehavior.Strict); GetCampaignGroupRequest request = new GetCampaignGroupRequest { ResourceName = new CampaignGroupName("[CUSTOMER]", "[CAMPAIGN_GROUP]").ToString(), }; CampaignGroup expectedResponse = new CampaignGroup { ResourceName = "resourceName2625949903", }; mockGrpcClient.Setup(x => x.GetCampaignGroupAsync(request, It.IsAny <CallOptions>())) .Returns(new Grpc.Core.AsyncUnaryCall <CampaignGroup>(Task.FromResult(expectedResponse), null, null, null, null)); CampaignGroupServiceClient client = new CampaignGroupServiceClientImpl(mockGrpcClient.Object, null); CampaignGroup response = await client.GetCampaignGroupAsync(request); Assert.AreEqual(expectedResponse, response); mockGrpcClient.VerifyAll(); }
/// <summary> /// Creates a new CampaignGroup in the specified client account. /// </summary> /// <param name="client">The Google Ads API client.</param> /// <param name="customerId">The Google Ads customer ID for which the call is made.</param> /// <returns>resource name of the newly created campaign group.</returns> private static String CreateCampaignGroup(GoogleAdsClient client, long customerId) { CampaignGroupServiceClient campaignGroupService = client.GetService( Services.V0.CampaignGroupService); CampaignGroup campaignGroup = new CampaignGroup() { Name = "Mars campaign group #" + ExampleUtilities.GetRandomString() }; CampaignGroupOperation op = new CampaignGroupOperation() { Create = campaignGroup }; MutateCampaignGroupsResponse response = campaignGroupService.MutateCampaignGroups( customerId.ToString(), new CampaignGroupOperation[] { op }); String groupResourceName = response.Results[0].ResourceName; Console.WriteLine($"Added campaign group with resource name: {groupResourceName}"); return(groupResourceName); }
/// <summary> /// Initialize this CampaignStage /// </summary> /// <param name="parent"></param> public void Initialize(CampaignGroup parent) { parentGroup = parent; }