/// <summary> /// Run the code example. /// </summary> /// <param name="service">An initialized Dfa Reporting service object /// </param> public override void Run(DfareportingService service) { long profileId = long.Parse(_T("INSERT_USER_PROFILE_ID_HERE")); // Limit the fields returned. String fields = "nextPageToken,placements(campaignId,id,name)"; PlacementsListResponse placements; String nextPageToken = null; do { // Create and execute the placements list request PlacementsResource.ListRequest request = service.Placements.List(profileId); request.Fields = fields; request.PageToken = nextPageToken; placements = request.Execute(); foreach (Placement placement in placements.Placements) { Console.WriteLine( "Placement with ID {0} and name \"{1}\" is associated with campaign ID {2}.", placement.Id, placement.Name, placement.CampaignId); } // Update the next page token nextPageToken = placements.NextPageToken; } while (placements.Placements.Any() && !String.IsNullOrEmpty(nextPageToken)); }
/// <summary> /// Run the code example. /// </summary> /// <param name="service">An initialized Dfa Reporting service object /// </param> public override void Run(DfareportingService service) { long reportId = long.Parse(_T("ENTER_REPORT_ID_HERE")); long profileId = long.Parse(_T("INSERT_USER_PROFILE_ID_HERE")); // Retrieve the specified report. Report report = service.Reports.Get(profileId, reportId).Execute(); // Look up the compatible fields for the report. CompatibleFields fields = service.Reports.CompatibleFields.Query(report, profileId).Execute(); // Display the compatible fields, assuming this is a standard report. ReportCompatibleFields reportFields = fields.ReportCompatibleFields; Console.WriteLine("Compatible dimensions:\n"); printDimensionNames(reportFields.Dimensions); Console.WriteLine("\nCompatible metrics:\n"); printMetricNames(reportFields.Metrics); Console.WriteLine("\nCompatible dimension filters:\n"); printDimensionNames(reportFields.DimensionFilters); Console.WriteLine("\nCompatible pivoted activity metrics:\n"); printMetricNames(reportFields.PivotedActivityMetrics); }
/// <summary> /// Run the code example. /// </summary> /// <param name="service">An initialized Dfa Reporting service object /// </param> public override void Run(DfareportingService service) { long advertiserId = long.Parse(_T("INSERT_ADVERTISER_ID_HERE")); long sizeId = long.Parse(_T("INSERT_SIZE_ID_HERE")); long profileId = long.Parse(_T("INSERT_USER_PROFILE_ID_HERE")); string pathToImageAssetFile = _T("INSERT_PATH_TO_IMAGE_ASSET_FILE_HERE"); Creative creative = new Creative(); creative.AdvertiserId = advertiserId; creative.Name = "Test image creative"; creative.Size = new Size() { Id = sizeId }; creative.Type = "IMAGE"; // Upload the image asset. CreativeAssetUtils assetUtils = new CreativeAssetUtils(service, profileId, advertiserId); CreativeAssetId imageAssetId = assetUtils.uploadAsset(pathToImageAssetFile, "IMAGE"); CreativeAsset imageAsset = new CreativeAsset(); imageAsset.AssetIdentifier = imageAssetId; imageAsset.Role = "PRIMARY"; // Add the creative assets. creative.CreativeAssets = new List<CreativeAsset>() { imageAsset }; Creative result = service.Creatives.Insert(creative, profileId).Execute(); // Display the new creative ID. Console.WriteLine("Image creative with ID {0} was created.", result.Id); }
/// <summary> /// Run the code example. /// </summary> /// <param name="service">An initialized Dfa Reporting service object /// </param> public override void Run(DfareportingService service) { long profileId = long.Parse(_T("INSERT_PROFILE_ID_HERE")); // Limit the fields returned. String fields = "nextPageToken,campaigns(id,name)"; CampaignsListResponse campaigns; String nextPageToken = null; do { // Create and execute the campaigns list request. CampaignsResource.ListRequest request = service.Campaigns.List(profileId); request.Fields = fields; request.PageToken = nextPageToken; campaigns = request.Execute(); foreach (Campaign campaign in campaigns.Campaigns) { Console.WriteLine("Campaign with ID {0} and name \"{1}\" was found.", campaign.Id, campaign.Name); } // Update the next page token. nextPageToken = campaigns.NextPageToken; } while (campaigns.Campaigns.Any() && !String.IsNullOrEmpty(nextPageToken)); }
/// <summary> /// Run the code example. /// </summary> /// <param name="service">An initialized Dfa Reporting service object /// </param> public override void Run(DfareportingService service) { long advertiserId = long.Parse(_T("ENTER_ADVERTISER_ID_HERE")); long profileId = long.Parse(_T("INSERT_PROFILE_ID_HERE")); // Limit the fields returned. String fields = "nextPageToken,creatives(id,name,type)"; CreativesListResponse creatives; String nextPageToken = null; do { // Create and execute the campaigns list request. CreativesResource.ListRequest request = service.Creatives.List(profileId); request.Active = true; request.AdvertiserId = advertiserId; request.Fields = fields; request.PageToken = nextPageToken; creatives = request.Execute(); foreach (Creative creative in creatives.Creatives) { Console.WriteLine("Found {0} creative with ID {1} and name \"{2}\".", creative.Type, creative.Id, creative.Name); } // Update the next page token. nextPageToken = creatives.NextPageToken; } while (creatives.Creatives.Any() && !String.IsNullOrEmpty(nextPageToken)); }
/// <summary> /// Run the code example. /// </summary> /// <param name="service">An initialized Dfa Reporting service object /// </param> public override void Run(DfareportingService service) { long profileId = long.Parse(_T("INSERT_PROFILE_ID_HERE")); // Limit the fields returned. String fields = "nextPageToken,subaccounts(id,name)"; SubaccountsListResponse subaccounts; String nextPageToken = null; do { // Create and execute the subaccounts list request. SubaccountsResource.ListRequest request = service.Subaccounts.List(profileId); request.Fields = fields; request.PageToken = nextPageToken; subaccounts = request.Execute(); foreach (Subaccount subaccount in subaccounts.Subaccounts) { Console.WriteLine("Subaccount with ID {0} and name \"{1}\" was found.", subaccount.Id, subaccount.Name); } // Update the next page token. nextPageToken = subaccounts.NextPageToken; } while (subaccounts.Subaccounts.Any() && !String.IsNullOrEmpty(nextPageToken)); }
/// <summary> /// Run the code example. /// </summary> /// <param name="service">An initialized Dfa Reporting service object /// </param> public override void Run(DfareportingService service) { long campaignId = long.Parse(_T("ENTER_CAMPAIGN_ID_HERE")); long placementId = long.Parse(_T("ENTER_PLACEMENT_ID_HERE")); long profileId = long.Parse(_T("INSERT_USER_PROFILE_ID_HERE")); // Generate the placement activity tags. PlacementsResource.GeneratetagsRequest request = service.Placements.Generatetags(profileId); request.CampaignId = campaignId; request.TagFormats = PlacementsResource.GeneratetagsRequest.TagFormatsEnum.PLACEMENTTAGSTANDARD; request.PlacementIds = placementId.ToString(); PlacementsGenerateTagsResponse response = request.Execute(); // Display the placement activity tags. foreach (PlacementTag tag in response.PlacementTags) { foreach (TagData tagData in tag.TagDatas) { Console.WriteLine("{0}:\n", tagData.Format); if (tagData.ImpressionTag != null) { Console.WriteLine(tagData.ImpressionTag); } if (tagData.ClickTag != null) { Console.WriteLine(tagData.ClickTag); } Console.WriteLine(); } } }
/// <summary> /// Run the code example. /// </summary> /// <param name="service">An initialized Dfa Reporting service object /// </param> public override void Run(DfareportingService service) { long advertiserId = long.Parse(_T("INSERT_ADVERTISER_ID_HERE")); long profileId = long.Parse(_T("INSERT_PROFILE_ID_HERE")); // Limit the fields returned. String fields = "nextPageToken,floodlightActivities(id,name)"; FloodlightActivitiesListResponse activities; String nextPageToken = null; do { // Create and execute the floodlight activities list request. FloodlightActivitiesResource.ListRequest request = service.FloodlightActivities.List(profileId); request.AdvertiserId = advertiserId; request.Fields = fields; request.PageToken = nextPageToken; activities = request.Execute(); foreach (FloodlightActivity activity in activities.FloodlightActivities) { Console.WriteLine("Floodlight activity with ID {0} and name \"{1}\"" + " was found.", activity.Id, activity.Name); } // Update the next page token. nextPageToken = activities.NextPageToken; } while (activities.FloodlightActivities.Any() && !String.IsNullOrEmpty(nextPageToken)); }
/// <summary> /// Run the code example. /// </summary> /// <param name="service">An initialized Dfa Reporting service object /// </param> public override void Run(DfareportingService service) { long reportId = long.Parse(_T("INSERT_REPORT_ID_HERE")); long profileId = long.Parse(_T("INSERT_USER_PROFILE_ID_HERE")); // Limit the fields returned. String fields = "nextPageToken,items(fileName,id,status)"; FileList files; String nextPageToken = null; do { // Create and execute the report files list request. ReportsResource.FilesResource.ListRequest request = service.Reports.Files.List(profileId, reportId); request.Fields = fields; request.PageToken = nextPageToken; files = request.Execute(); foreach (File file in files.Items) { Console.WriteLine("Report file with ID {0} and file name \"{1}\" has status \"{2}\".", file.Id, file.FileName, file.Status); } // Update the next page token. nextPageToken = files.NextPageToken; } while (files.Items.Any() && !String.IsNullOrEmpty(nextPageToken)); }
/// <summary> /// Run the code example. /// </summary> /// <param name="service">An initialized Dfa Reporting service object /// </param> public override void Run(DfareportingService service) { long advertiserId = long.Parse(_T("INSERT_ADVERTISER_ID_HERE")); long profileId = long.Parse(_T("INSERT_USER_PROFILE_ID_HERE")); String campaignName = _T("INSERT_CAMPAIGN_NAME_HERE"); String landingPageName = _T("INSERT_LANDING_PAGE_NAME_HERE"); String url = _T("INSERT_LANDING_PAGE_URL_HERE"); // Create the campaign structure. Campaign campaign = new Campaign(); campaign.Name = campaignName; campaign.AdvertiserId = advertiserId; campaign.Archived = false; // Set the campaign start date. This example uses today's date. campaign.StartDate = DfaReportingDateConverterUtil.convertToDateString(DateTime.Now); // Set the campaign end date. This example uses one month from today's date. campaign.EndDate = DfaReportingDateConverterUtil.convertToDateString(DateTime.Now.AddMonths(1)); // Insert the campaign. Campaign result = service.Campaigns.Insert(campaign, profileId, landingPageName, url).Execute(); // Display the new campaign ID. Console.WriteLine("Campaign with ID {0} was created.", result.Id); }
/// <summary> /// Run the code example. /// </summary> /// <param name="service">An initialized Dfa Reporting service object /// </param> public override void Run(DfareportingService service) { long profileId = long.Parse(_T("INSERT_PROFILE_ID_HERE")); // Limit the fields returned. String fields = "nextPageToken,advertisers(id,floodlightConfigurationId,name)"; AdvertisersListResponse result; String nextPageToken = null; do { // Create and execute the advertiser list request. AdvertisersResource.ListRequest request = service.Advertisers.List(profileId); request.Fields = fields; request.PageToken = nextPageToken; result = request.Execute(); foreach (Advertiser advertiser in result.Advertisers) { Console.WriteLine("Advertiser with ID {0}, name \"{1}\", and" + " floodlight configuration ID {2} was found.", advertiser.Id, advertiser.Name, advertiser.FloodlightConfigurationId); } // Update the next page token. nextPageToken = result.NextPageToken; } while (result.Advertisers.Any() && !String.IsNullOrEmpty(nextPageToken)); }
/// <summary> /// Run the code example. /// </summary> /// <param name="service">An initialized Dfa Reporting service object /// </param> public override void Run(DfareportingService service) { long profileId = long.Parse(_T("INSERT_USER_PROFILE_ID_HERE")); string reportName = _T("INSERT_REPORT_NAME_HERE"); // Create a date range to report on. DateRange dateRange = new DateRange(); dateRange.RelativeDateRange = "YESTERDAY"; // Create a dimension to report on. SortedDimension dimension = new SortedDimension(); dimension.Name = "dfa:campaign"; // Create the criteria for the report. Report.CriteriaData criteria = new Report.CriteriaData(); criteria.DateRange = dateRange; criteria.Dimensions = new List<SortedDimension>() { dimension }; criteria.MetricNames = new List<string>() { "dfa:clicks" }; // Create the report. Report report = new Report(); report.Criteria = criteria; report.Name = reportName; report.Type = "STANDARD"; // Insert the report. Report result = service.Reports.Insert(report, profileId).Execute(); // Display the new report ID. Console.WriteLine("Standard report with ID {0} was created.", result.Id); }
/// <summary> /// Run the code example. /// </summary> /// <param name="service">An initialized Dfa Reporting service object /// </param> public override void Run(DfareportingService service) { long campaignId = long.Parse(_T("INSERT_CAMPAIGN_ID_HERE")); long dfaSiteId = long.Parse(_T("INSERT_SITE_ID_HERE")); long profileId = long.Parse(_T("INSERT_USER_PROFILE_ID_HERE")); string placementGroupName = _T("INSERT_PLACEMENT_GROUP_NAME_HERE"); // Retrieve the campaign. Campaign campaign = service.Campaigns.Get(profileId, campaignId).Execute(); // Create a pricing schedule. PricingSchedule pricingSchedule = new PricingSchedule(); pricingSchedule.EndDate = campaign.EndDate; pricingSchedule.PricingType = "PRICING_TYPE_CPM"; pricingSchedule.StartDate = campaign.StartDate; // Create the placement group. PlacementGroup placementGroup = new PlacementGroup(); placementGroup.CampaignId = campaignId; placementGroup.Name = placementGroupName; placementGroup.PlacementGroupType = "PLACEMENT_PACKAGE"; placementGroup.PricingSchedule = pricingSchedule; placementGroup.SiteId = dfaSiteId; // Insert the placement. PlacementGroup result = service.PlacementGroups.Insert(placementGroup, profileId).Execute(); // Display the new placement ID. Console.WriteLine("Placement group with ID {0} was created.", result.Id); }
/// <summary> /// Run the code example. /// </summary> /// <param name="service">An initialized Dfa Reporting service object /// </param> public override void Run(DfareportingService service) { long profileId = long.Parse(_T("INSERT_PROFILE_ID_HERE")); // Limit the fields returned. String fields = "nextPageToken,ads(advertiserId,id,name)"; AdsListResponse result; String nextPageToken = null; do { // Create and execute the ad list request. AdsResource.ListRequest request = service.Ads.List(profileId); request.Active = true; request.Fields = fields; request.PageToken = nextPageToken; result = request.Execute(); foreach (Ad ad in result.Ads) { Console.WriteLine( "Ad with ID {0} and name \"{1}\" is associated with advertiser" + " ID {2}.", ad.Id, ad.Name, ad.AdvertiserId); } // Update the next page token. nextPageToken = result.NextPageToken; } while (result.Ads.Any() && !String.IsNullOrEmpty(nextPageToken)); }
/// <summary> /// Run the code example. /// </summary> /// <param name="service">An initialized Dfa Reporting service object /// </param> public override void Run(DfareportingService service) { long campaignId = long.Parse(_T("INSERT_CAMPAIGN_ID_HERE")); long creativeId = long.Parse(_T("INSERT_CREATIVE_ID_HERE")); long placementId = long.Parse(_T("INSERT_PLACEMENT_ID_HERE")); long profileId = long.Parse(_T("INSERT_PROFILE_ID_HERE")); String adName = _T("INSERT_AD_NAME_HERE"); // Retrieve the campaign. Campaign campaign = service.Campaigns.Get(profileId, campaignId).Execute(); // Create a click-through URL. ClickThroughUrl clickThroughUrl = new ClickThroughUrl(); clickThroughUrl.DefaultLandingPage = true; // Create a creative assignment. CreativeAssignment creativeAssignment = new CreativeAssignment(); creativeAssignment.Active = true; creativeAssignment.CreativeId = creativeId; creativeAssignment.ClickThroughUrl = clickThroughUrl; // Create a placement assignment. PlacementAssignment placementAssignment = new PlacementAssignment(); placementAssignment.Active = true; placementAssignment.PlacementId = placementId; // Create a creative rotation. CreativeRotation creativeRotation = new CreativeRotation(); creativeRotation.CreativeAssignments = new List<CreativeAssignment>() { creativeAssignment }; // Create a delivery schedule. DeliverySchedule deliverySchedule = new DeliverySchedule(); deliverySchedule.ImpressionRatio = 1; deliverySchedule.Priority = "AD_PRIORITY_01"; DateTime startDate = DateTime.Now; DateTime endDate = Convert.ToDateTime(campaign.EndDate); // Create a rotation group. Ad rotationGroup = new Ad(); rotationGroup.Active = true; rotationGroup.CampaignId = campaignId; rotationGroup.CreativeRotation = creativeRotation; rotationGroup.DeliverySchedule = deliverySchedule; rotationGroup.StartTime = startDate; rotationGroup.EndTime = endDate; rotationGroup.Name = adName; rotationGroup.PlacementAssignments = new List<PlacementAssignment>() { placementAssignment }; rotationGroup.Type = "AD_SERVING_STANDARD_AD"; // Insert the rotation group. Ad result = service.Ads.Insert(rotationGroup, profileId).Execute(); // Display the new ad ID. Console.WriteLine("Ad with ID {0} was created.", result.Id); }
/// <summary> /// Run the code example. /// </summary> /// <param name="service">An initialized Dfa Reporting service object /// </param> public override void Run(DfareportingService service) { long profileId = long.Parse(_T("INSERT_PROFILE_ID_HERE")); // Limit the fields returned. String fields = "nextPageToken,userRoles(accountId,id,name,subaccountId)"; UserRolesListResponse roles; String nextPageToken = null; do { // Create and execute the user roles list request. UserRolesResource.ListRequest request = service.UserRoles.List(profileId); request.Fields = fields; request.PageToken = nextPageToken; roles = request.Execute(); foreach (UserRole role in roles.UserRoles) { Console.WriteLine("User role with ID {0} and name \"{1}\" was found.", role.Id, role.Name); } // Update the next page token. nextPageToken = roles.NextPageToken; } while (roles.UserRoles.Any() && !String.IsNullOrEmpty(nextPageToken)); }
/// <summary> /// Run the code example. /// </summary> /// <param name="service">An initialized Dfa Reporting service object /// </param> public override void Run(DfareportingService service) { long advertiserId = long.Parse(_T("INSERT_ADVERTISER_ID_HERE")); long profileId = long.Parse(_T("INSERT_PROFILE_ID_HERE")); // Limit the fields returned. String fields = "nextPageToken,changeLogs(action,fieldName,oldValue,newValue)"; ChangeLogsListResponse changeLogs; String nextPageToken = null; do { // Create and execute the change logs list request ChangeLogsResource.ListRequest request = service.ChangeLogs.List(profileId); request.ObjectIds = advertiserId.ToString(); request.ObjectType = ChangeLogsResource.ListRequest.ObjectTypeEnum.OBJECTADVERTISER; request.Fields = fields; request.PageToken = nextPageToken; changeLogs = request.Execute(); foreach (ChangeLog changeLog in changeLogs.ChangeLogs) { Console.WriteLine("{0}: Field \"{1}\" from \"{2}\" to \"{3}\".", changeLog.Action, changeLog.FieldName, changeLog.OldValue, changeLog.NewValue); } // Update the next page token. nextPageToken = changeLogs.NextPageToken; } while (changeLogs.ChangeLogs.Any() && !String.IsNullOrEmpty(nextPageToken)); }
/// <summary> /// Run the code example. /// </summary> /// <param name="service">An initialized Dfa Reporting service object /// </param> public override void Run(DfareportingService service) { long advertiserId = long.Parse(_T("INSERT_ADVERTISER_ID_HERE")); long profileId = long.Parse(_T("INSERT_USER_PROFILE_ID_HERE")); string videoAssetName = _T("INSERT_VIDEO_ASSET_NAME_HERE"); string pathToVideoAssetFile = _T("INSERT_PATH_TO_VIDEO_ASSET_FILE_HERE"); Creative creative = new Creative(); creative.AdvertiserId = advertiserId; creative.Name = "Test in-stream video creative"; creative.Type = "INSTREAM_VIDEO"; // Upload the video asset. CreativeAssetUtils assetUtils = new CreativeAssetUtils(service, profileId, advertiserId); CreativeAssetId videoAssetId = assetUtils.uploadAsset(pathToVideoAssetFile, "VIDEO"); CreativeAsset videoAsset = new CreativeAsset(); videoAsset.AssetIdentifier = videoAssetId; videoAsset.Role = "PARENT_VIDEO"; // Add the creative assets. creative.CreativeAssets = new List<CreativeAsset>() { videoAsset }; Creative result = service.Creatives.Insert(creative, profileId).Execute(); // Display the new creative ID. Console.WriteLine("In-stream video creative with ID {0} was created.", result.Id); }
/// <summary> /// Run the code example. /// </summary> /// <param name="service">An initialized Dfa Reporting service object /// </param> public override void Run(DfareportingService service) { // Retrieve and print all user profiles for the current authorized user. UserProfileList profiles = service.UserProfiles.List().Execute(); foreach (UserProfile profile in profiles.Items) { Console.WriteLine(profile.UserName); } }
/// <summary> /// Run the code example. /// </summary> /// <param name="service">An initialized Dfa Reporting service object /// </param> public override void Run(DfareportingService service) { long profileId = long.Parse(_T("INSERT_USER_PROFILE_ID_HERE")); // Limit the fields returned. String fields = "nextPageToken,placementStrategies(id,name)"; PlacementStrategiesListResponse strategies; String nextPageToken = null; do { // Create and execute the placement strategies list request PlacementStrategiesResource.ListRequest request = service.PlacementStrategies.List(profileId); request.Fields = fields; request.PageToken = nextPageToken; strategies = request.Execute(); foreach (PlacementStrategy strategy in strategies.PlacementStrategies) { Console.WriteLine("Found placement strategy with ID {0} and name \"{1}\".", strategy.Id, strategy.Name); } // Update the next page token nextPageToken = strategies.NextPageToken; } while (strategies.PlacementStrategies.Any() && !String.IsNullOrEmpty(nextPageToken)); }
/// <summary> /// Run the code example. /// </summary> /// <param name="service">An initialized Dfa Reporting service object /// </param> public override void Run(DfareportingService service) { long profileId = long.Parse(_T("INSERT_USER_PROFILE_ID_HERE")); // Limit the fields returned. String fields = "nextPageToken,sites(id,keyName)"; SitesListResponse sites; String nextPageToken = null; do { // Create and execute the content categories list request SitesResource.ListRequest request = service.Sites.List(profileId); request.Fields = fields; request.PageToken = nextPageToken; sites = request.Execute(); foreach (Site site in sites.Sites) { Console.WriteLine("Found site with ID {0} and key name \"{1}\".", site.Id, site.KeyName); } // Update the next page token nextPageToken = sites.NextPageToken; } while (sites.Sites.Any() && !String.IsNullOrEmpty(nextPageToken)); }
/// <summary> /// Run the code example. /// </summary> /// <param name="service">An initialized Dfa Reporting service object /// </param> public override void Run(DfareportingService service) { long parentUserRoleId = long.Parse(_T("INSERT_PARENT_USER_ROLE_ID_HERE")); long permission1Id = long.Parse(_T("INSERT_FIRST_PERMISSION_ID_HERE")); long permission2Id = long.Parse(_T("INSERT_SECOND_PERMISSIONS_ID_HERE")); long profileId = long.Parse(_T("INSERT_PROFILE_ID_HERE")); long subaccountId = long.Parse(_T("INSERT_SUBACCOUNT_ID_HERE")); String userRoleName = _T("INSERT_USER_ROLE_NAME_HERE"); // Create user role structure. UserRole userRole = new UserRole(); userRole.Name = userRoleName; userRole.SubaccountId = subaccountId; userRole.ParentUserRoleId = parentUserRoleId; // Create a permission object to represent each permission this user role // has. UserRolePermission permission1 = new UserRolePermission(); permission1.Id = permission1Id; UserRolePermission permission2 = new UserRolePermission(); permission2.Id = permission2Id; List<UserRolePermission> permissions = new List<UserRolePermission> { permission1, permission2 }; // Add the permissions to the user role. userRole.Permissions = permissions; // Create user role. UserRole result = service.UserRoles.Insert(userRole, profileId).Execute(); // Display user role ID. Console.WriteLine("User role with ID {0} was created.", result.Id); }
/// <summary> /// Run the code example. /// </summary> /// <param name="service">An initialized Dfa Reporting service object /// </param> public override void Run(DfareportingService service) { long profileId = long.Parse(_T("INSERT_USER_PROFILE_ID_HERE")); // Limit the fields returned. String fields = "nextPageToken,items(id,name,type)"; ReportList reports; String nextPageToken = null; do { // Create and execute the report list request. ReportsResource.ListRequest request = service.Reports.List(profileId); request.Fields = fields; request.PageToken = nextPageToken; reports = request.Execute(); foreach (Report report in reports.Items) { Console.WriteLine("{0} report with ID {1} and name \"{2}\" was found.", report.Type, report.Id, report.Name); } // Update the next page token. nextPageToken = reports.NextPageToken; } while (reports.Items.Any() && !String.IsNullOrEmpty(nextPageToken)); }
/// <summary> /// Run the code example. /// </summary> /// <param name="service">An initialized Dfa Reporting service object /// </param> public override void Run(DfareportingService service) { long profileId = long.Parse(_T("INSERT_PROFILE_ID_HERE")); // Retrieve the specified user profile. UserProfile profile = service.UserProfiles.Get(profileId).Execute(); Console.WriteLine("User profile with ID {0} and name \"{1}\" was found.", profile.ProfileId, profile.UserName); }
/// <summary> /// Run the code example. /// </summary> /// <param name="service">An initialized Dfa Reporting service object /// </param> public override void Run(DfareportingService service) { long reportId = long.Parse(_T("ENTER_REPORT_ID_HERE")); long profileId = long.Parse(_T("INSERT_USER_PROFILE_ID_HERE")); // Delete the report. service.Reports.Delete(profileId, reportId).Execute(); // Display the new report ID. Console.WriteLine("Report with ID {0} was successfully deleted.", reportId); }
/// <summary> /// Run the code example. /// </summary> /// <param name="service">An initialized Dfa Reporting service object /// </param> public override void Run(DfareportingService service) { long reportId = long.Parse(_T("INSERT_REPORT_ID_HERE")); long profileId = long.Parse(_T("INSERT_USER_PROFILE_ID_HERE")); // Run the report. File file = service.Reports.Run(profileId, reportId).Execute(); Console.WriteLine("Report file with ID {0} is in status \"{1}\".", file.Id, file.Status); }
/// <summary> /// Run the code example. /// </summary> /// <param name="service">An initialized Dfa Reporting service object /// </param> public override void Run(DfareportingService service) { long encryptionEntityId = long.Parse(_T("INSERT_ENCRYPTION_ENTITY_TYPE")); long floodlightActivityId = long.Parse(_T("INSERT_FLOODLIGHT_ACTIVITY_ID_HERE")); long profileId = long.Parse(_T("INSERT_USER_PROFILE_ID_HERE")); string conversionUserId = _T("INSERT_CONVERSION_USER_ID_HERE"); string encryptionEntityType = _T("INSERT_ENCRYPTION_ENTITY_TYPE_HERE"); string encryptionSource = _T("INSERT_ENCRYPTION_SOURCE_HERE"); // Generate a timestamp in milliseconds since Unix epoch. TimeSpan timeSpan = DateTime.UtcNow - new DateTime(1970, 1, 1); long currentTimeInMilliseconds = (long) timeSpan.TotalMilliseconds; // Find the Floodlight configuration ID based on the provided activity ID. FloodlightActivity floodlightActivity = service.FloodlightActivities.Get(profileId, floodlightActivityId).Execute(); long floodlightConfigurationId = (long) floodlightActivity.FloodlightConfigurationId; // Create the conversion. Conversion conversion = new Conversion(); conversion.EncryptedUserId = conversionUserId; conversion.FloodlightActivityId = floodlightActivityId; conversion.FloodlightConfigurationId = floodlightConfigurationId; conversion.Ordinal = currentTimeInMilliseconds.ToString(); conversion.TimestampMicros = currentTimeInMilliseconds * 1000; // Create the encryption info. EncryptionInfo encryptionInfo = new EncryptionInfo(); encryptionInfo.EncryptionEntityId = encryptionEntityId; encryptionInfo.EncryptionEntityType = encryptionEntityType; encryptionInfo.EncryptionSource = encryptionSource; // Insert the conversion. ConversionsBatchInsertRequest request = new ConversionsBatchInsertRequest(); request.Conversions = new List<Conversion>() { conversion }; request.EncryptionInfo = encryptionInfo; ConversionsBatchInsertResponse response = service.Conversions.Batchinsert(request, profileId).Execute(); // Handle the batchinsert response. if (!response.HasFailures.Value) { Console.WriteLine("Successfully inserted conversion for encrypted user ID {0}.", conversionUserId); } else { Console.WriteLine("Error(s) inserting conversion for encrypted user ID {0}:", conversionUserId); ConversionStatus status = response.Status[0]; foreach(ConversionError error in status.Errors) { Console.WriteLine("\t[{0}]: {1}", error.Code, error.Message); } } }
/// <summary> /// Run the code example. /// </summary> /// <param name="service">An initialized Dfa Reporting service object /// </param> public override void Run(DfareportingService service) { long advertiserId = long.Parse(_T("INSERT_ADVERTISER_ID_HERE")); long sizeId = long.Parse(_T("INSERT_SIZE_ID_HERE")); long profileId = long.Parse(_T("INSERT_USER_PROFILE_ID_HERE")); string pathToHtmlAssetFile = _T("INSERT_PATH_TO_HTML_ASSET_FILE_HERE"); string pathToImageAssetFile = _T("INSERT_PATH_TO_IMAGE_ASSET_FILE_HERE"); Creative creative = new Creative(); creative.AdvertiserId = advertiserId; creative.Name = "Test enhanced banner creative"; creative.Size = new Size() { Id = sizeId }; creative.Type = "ENHANCED_BANNER"; // Upload the HTML asset. CreativeAssetUtils assetUtils = new CreativeAssetUtils(service, profileId, advertiserId); CreativeAssetId htmlAssetId = assetUtils.uploadAsset(pathToHtmlAssetFile, "HTML"); CreativeAsset htmlAsset = new CreativeAsset(); htmlAsset.AssetIdentifier = htmlAssetId; htmlAsset.Role = "PRIMARY"; htmlAsset.WindowMode = "TRANSPARENT"; // Upload the backup image asset. CreativeAssetId backupImageAssetId = assetUtils.uploadAsset(pathToImageAssetFile, "HTML_IMAGE"); CreativeAsset backupImageAsset = new CreativeAsset(); backupImageAsset.AssetIdentifier = backupImageAssetId; backupImageAsset.Role = "BACKUP_IMAGE"; // Add the creative assets. creative.CreativeAssets = new List<CreativeAsset>() { htmlAsset, backupImageAsset }; // Configure the backup image. creative.BackupImageClickThroughUrl = "https://www.google.com"; creative.BackupImageReportingLabel = "backup"; creative.BackupImageTargetWindow = new TargetWindow() { TargetWindowOption = "NEW_WINDOW" }; // Add a click tag. ClickTag clickTag = new ClickTag(); clickTag.Name = "clickTag"; clickTag.EventName = "exit"; clickTag.Value = "https://www.google.com"; creative.ClickTags = new List<ClickTag>() { clickTag }; Creative result = service.Creatives.Insert(creative, profileId).Execute(); // Display the new creative ID. Console.WriteLine("Enhanced banner creative with ID {0} was created.", result.Id); }
/// <summary> /// Run the code example. /// </summary> /// <param name="service">An initialized Dfa Reporting service object /// </param> public override void Run(DfareportingService service) { long advertiserId = long.Parse(_T("INSERT_ADVERTISER_ID_HERE")); long sizeId = long.Parse(_T("INSERT_SIZE_ID_HERE")); long profileId = long.Parse(_T("INSERT_USER_PROFILE_ID_HERE")); string pathToImageAssetFile = _T("INSERT_PATH_TO_IMAGE_ASSET_FILE_HERE"); string pathToImageAsset2File = _T("INSERT_PATH_TO_IMAGE_ASSET_FILE_HERE"); Creative creative = new Creative(); creative.AdvertiserId = advertiserId; creative.AutoAdvanceImages = true; creative.Name = "Test enhanced image creative"; creative.Size = new Size() { Id = sizeId }; creative.Type = "ENHANCED_IMAGE"; // Upload the first image asset. CreativeAssetUtils assetUtils = new CreativeAssetUtils(service, profileId, advertiserId); CreativeAssetId imageAsset1Id = assetUtils.uploadAsset(pathToImageAssetFile, "HTML_IMAGE"); CreativeAsset imageAsset1 = new CreativeAsset(); imageAsset1.AssetIdentifier = imageAsset1Id; imageAsset1.Role = "PRIMARY"; // Upload the second image asset. CreativeAssetId imageAsset2Id = assetUtils.uploadAsset(pathToImageAsset2File, "HTML_IMAGE"); CreativeAsset imageAsset2 = new CreativeAsset(); imageAsset2.AssetIdentifier = imageAsset2Id; imageAsset2.Role = "PRIMARY"; // Add the creative assets. creative.CreativeAssets = new List<CreativeAsset>() { imageAsset1, imageAsset2 }; // Create a click tag for the first image asset. ClickTag clickTag1 = new ClickTag(); clickTag1.Name = imageAsset1Id.Name; clickTag1.EventName = imageAsset1Id.Name; // Create a click tag for the second image asset. ClickTag clickTag2 = new ClickTag(); clickTag2.Name = imageAsset2Id.Name; clickTag2.EventName = imageAsset2Id.Name; // Add the click tags. creative.ClickTags = new List<ClickTag>() { clickTag1, clickTag2 }; Creative result = service.Creatives.Insert(creative, profileId).Execute(); // Display the new creative ID. Console.WriteLine("Enhanced image creative with ID {0} was created.", result.Id); }
/// <summary> /// Run the code example. /// </summary> /// <param name="service">An initialized Dfa Reporting service object /// </param> public override void Run(DfareportingService service) { long fileId = long.Parse(_T("INSERT_FILE_ID_HERE")); long reportId = long.Parse(_T("ENTER_REPORT_ID_HERE")); // Download the file. using (Stream fileStream = new MemoryStream()) { service.Files.Get(reportId, fileId).Download(fileStream); // Display the file contents. fileStream.Position = 0; StreamReader reader = new StreamReader(fileStream, Encoding.UTF8); Console.WriteLine(reader.ReadToEnd()); } }
/// <summary> /// Run the code example. /// </summary> /// <param name="service">An initialized Dfa Reporting service object /// </param> public override void Run(DfareportingService service) { long parentUserRoleId = long.Parse(_T("INSERT_PARENT_USER_ROLE_ID_HERE")); long permission1Id = long.Parse(_T("INSERT_FIRST_PERMISSION_ID_HERE")); long permission2Id = long.Parse(_T("INSERT_SECOND_PERMISSIONS_ID_HERE")); long profileId = long.Parse(_T("INSERT_PROFILE_ID_HERE")); long subaccountId = long.Parse(_T("INSERT_SUBACCOUNT_ID_HERE")); String userRoleName = _T("INSERT_USER_ROLE_NAME_HERE"); // Create user role structure. UserRole userRole = new UserRole(); userRole.Name = userRoleName; userRole.SubaccountId = subaccountId; userRole.ParentUserRoleId = parentUserRoleId; // Create a permission object to represent each permission this user role // has. UserRolePermission permission1 = new UserRolePermission(); permission1.Id = permission1Id; UserRolePermission permission2 = new UserRolePermission(); permission2.Id = permission2Id; List <UserRolePermission> permissions = new List <UserRolePermission> { permission1, permission2 }; // Add the permissions to the user role. userRole.Permissions = permissions; // Create user role. UserRole result = service.UserRoles.Insert(userRole, profileId).Execute(); // Display user role ID. Console.WriteLine("User role with ID {0} was created.", result.Id); }
private LandingPage getAdvertiserLandingPage(DfareportingService service, long profileId, long advertiserId) { // Retrieve a single landing page from the specified advertiser. AdvertiserLandingPagesResource.ListRequest listRequest = service.AdvertiserLandingPages.List(profileId); listRequest.AdvertiserIds = new List <string>() { advertiserId.ToString() }; listRequest.MaxResults = 1; AdvertiserLandingPagesListResponse landingPages = listRequest.Execute(); if (landingPages.LandingPages == null || landingPages.LandingPages.Count == 0) { throw new InvalidOperationException( String.Format("No landing pages found for advertiser with ID {0}.", advertiserId)); } return(landingPages.LandingPages[0]); }
/// <summary> /// Retrieves a list of browsers. /// Documentation https://developers.google.com/dfareporting/v2.8/reference/browsers/list /// Generation Note: This does not always build corectly. Google needs to standardise things I need to figuer out which ones are wrong. /// </summary> /// <param name="service">Authenticated Dfareporting service.</param> /// <param name="profileId">User profile ID associated with this request.</param> /// <returns>BrowsersListResponseResponse</returns> public static BrowsersListResponse List(DfareportingService service, string profileId) { try { // Initial validation. if (service == null) { throw new ArgumentNullException("service"); } if (profileId == null) { throw new ArgumentNullException(profileId); } // Make the request. return(service.Browsers.List(profileId).Execute()); } catch (Exception ex) { throw new Exception("Request Browsers.List failed.", ex); } }
private void DirectDownloadFile(DfareportingService service, long reportId, long fileId) { // Retrieve the file metadata. File file = service.Files.Get(reportId, fileId).Execute(); if ("REPORT_AVAILABLE".Equals(file.Status)) { // Create a get request. FilesResource.GetRequest getRequest = service.Files.Get(reportId, fileId); // Optional: adjust the chunk size used when downloading the file. // getRequest.MediaDownloader.ChunkSize = MediaDownloader.MaximumChunkSize; // Execute the get request and download the file. using (System.IO.FileStream outFile = new System.IO.FileStream(GenerateFileName(file), System.IO.FileMode.Create, System.IO.FileAccess.Write)) { getRequest.Download(outFile); Console.WriteLine("File {0} downloaded to {1}", file.Id, outFile.Name); } } }
/// <summary> /// Run the code example. /// </summary> /// <param name="service">An initialized Dfa Reporting service object /// </param> public override void Run(DfareportingService service) { long advertiserId = long.Parse(_T("INSERT_ADVERTISER_ID_HERE")); long sizeId = long.Parse(_T("INSERT_SIZE_ID_HERE")); long profileId = long.Parse(_T("INSERT_USER_PROFILE_ID_HERE")); string pathToImageAssetFile = _T("INSERT_PATH_TO_IMAGE_ASSET_FILE_HERE"); Creative creative = new Creative(); creative.AdvertiserId = advertiserId; creative.Name = "Test image display creative"; creative.Size = new Size() { Id = sizeId }; creative.Type = "DISPLAY"; // Upload the image asset. CreativeAssetUtils assetUtils = new CreativeAssetUtils(service, profileId, advertiserId); CreativeAssetId imageAssetId = assetUtils.uploadAsset(pathToImageAssetFile, "HTML_IMAGE").AssetIdentifier; CreativeAsset imageAsset = new CreativeAsset(); imageAsset.AssetIdentifier = imageAssetId; imageAsset.Role = "PRIMARY"; // Add the creative assets. creative.CreativeAssets = new List <CreativeAsset>() { imageAsset }; Creative result = service.Creatives.Insert(creative, profileId).Execute(); // Display the new creative ID. Console.WriteLine("Image display creative with ID {0} was created.", result.Id); }
/// <summary> /// Updates an existing site. This method supports patch semantics. /// Documentation https://developers.google.com/dfareporting/v2.7/reference/sites/patch /// Generation Note: This does not always build corectly. Google needs to standardise things I need to figuer out which ones are wrong. /// </summary> /// <param name="service">Authenticated Dfareporting service.</param> /// <param name="profileId">User profile ID associated with this request.</param> /// <param name="id">Site ID.</param> /// <param name="body">A valid Dfareporting v2.7 body.</param> /// <returns>SiteResponse</returns> public static Site Patch(DfareportingService service, string profileId, string id, Site body) { try { // Initial validation. if (service == null) throw new ArgumentNullException("service"); if (body == null) throw new ArgumentNullException("body"); if (profileId == null) throw new ArgumentNullException(profileId); if (id == null) throw new ArgumentNullException(id); // Make the request. return service.Sites.Patch(body, profileId, id).Execute(); } catch (Exception ex) { throw new Exception("Request Sites.Patch failed.", ex); } }
/// <summary> /// Run the code example. /// </summary> /// <param name="service">An initialized Dfa Reporting service object /// </param> public override void Run(DfareportingService service) { int groupNumber = int.Parse(_T("INSERT_GROUP_NUMBER_HERE")); long advertiserId = long.Parse(_T("INSERT_ADVERTISER_ID_HERE")); long profileId = long.Parse(_T("INSERT_USER_PROFILE_ID_HERE")); string creativeGroupName = _T("INSERT_CREATIVE_GROUP_NAME_HERE"); // Create the creative group. CreativeGroup creativeGroup = new CreativeGroup(); creativeGroup.Name = creativeGroupName; creativeGroup.GroupNumber = groupNumber; creativeGroup.AdvertiserId = advertiserId; // Insert the creative group. CreativeGroup result = service.CreativeGroups.Insert(creativeGroup, profileId).Execute(); // Display the new creative group ID. Console.WriteLine("Creative group with ID {0} was created.", result.Id); }
/// <summary> /// Run the code example. /// </summary> /// <param name="service">An initialized Dfa Reporting service object /// </param> public override void Run(DfareportingService service) { long campaignId = long.Parse(_T("INSERT_CAMPAIGN_ID_HERE")); long creativeId = long.Parse(_T("INSERT_CREATIVE_ID_HERE")); long profileId = long.Parse(_T("INSERT_USER_PROFILE_ID_HERE")); // [START create_association] MOE:strip_line // Create the campaign creative association structure. CampaignCreativeAssociation association = new CampaignCreativeAssociation(); association.CreativeId = creativeId; // Insert the association. CampaignCreativeAssociation result = service.CampaignCreativeAssociations.Insert(association, profileId, campaignId).Execute(); // [END create_association] MOE:strip_line // Display a success message. Console.WriteLine("Creative with ID {0} is now associated with campaign {1}.", result.CreativeId, campaignId); }
private Report FindReport(DfareportingService service, long profileId) { Report target = null; ReportList reports; String nextPageToken = null; do { // Create and execute the reports list request. ReportsResource.ListRequest request = service.Reports.List(profileId); request.PageToken = nextPageToken; reports = request.Execute(); foreach (Report report in reports.Items) { if (IsTargetReport(report)) { target = report; break; } } // Update the next page token. nextPageToken = reports.NextPageToken; } while (target == null && reports.Items.Any() && !String.IsNullOrEmpty(nextPageToken)); if (target != null) { Console.WriteLine("Found report {0} with name \"{1}\".", target.Id, target.Name); return(target); } Console.WriteLine("Unable to find report for profile ID {0}.", profileId); return(null); }
/// <summary> /// Run the code example. /// </summary> /// <param name="service">An initialized Dfa Reporting service object /// </param> public override void Run(DfareportingService service) { long campaignId = long.Parse(_T("INSERT_CAMPAIGN_ID_HERE")); long profileId = long.Parse(_T("INSERT_USER_PROFILE_ID_HERE")); String eventTagName = _T("INSERT_EVENT_TAG_NAME_HERE"); String eventTagUrl = _T("INSERT_EVENT_TAG_URL_HERE"); // Create the event tag structure. EventTag eventTag = new EventTag(); eventTag.CampaignId = campaignId; eventTag.Name = eventTagName; eventTag.Status = "ENABLED"; eventTag.Type = "CLICK_THROUGH_EVENT_TAG"; eventTag.Url = eventTagUrl; // Insert the campaign. EventTag result = service.EventTags.Insert(eventTag, profileId).Execute(); // Display the new campaign ID. Console.WriteLine("Event Tag with ID {0} was created.", result.Id); }
/// <summary> /// Run the code example. /// </summary> /// <param name="service">An initialized Dfa Reporting service object /// </param> public override void Run(DfareportingService service) { long profileId = long.Parse(_T("INSERT_USER_PROFILE_ID_HERE")); long reportId = long.Parse(_T("INSERT_REPORT_ID_HERE")); // 1. Find a file to download. File file = FindFile(service, profileId, reportId); if (file != null) { // 2. (optional) Generate browser URL. GenerateBrowserUrl(service, reportId, file.Id.Value); // 3. Directly download the file DirectDownloadFile(service, reportId, file.Id.Value); } else { Console.WriteLine( "No file found for profile ID {0} and report ID {1}.", profileId, reportId); } }
/// <summary> /// Run the code example. /// </summary> /// <param name="service">An initialized Dfa Reporting service object /// </param> public override void Run(DfareportingService service) { long creativeFieldId = long.Parse(_T("ENTER_CREATIVE_FIELD_ID_HERE")); long profileId = long.Parse(_T("INSERT_PROFILE_ID_HERE")); CreativeFieldValuesListResponse values; String nextPageToken = null; do { // Create and execute the creative field values list request. CreativeFieldValuesResource.ListRequest request = service.CreativeFieldValues.List(profileId, creativeFieldId); request.PageToken = nextPageToken; values = request.Execute(); foreach (CreativeFieldValue value in values.CreativeFieldValues) { Console.WriteLine("Found creative field value with ID {0} and value \"{1}\".", value.Id, value.Value); } // Update the next page token. nextPageToken = values.NextPageToken; } while (values.CreativeFieldValues.Any() && !String.IsNullOrEmpty(nextPageToken)); }
/// <summary> /// Run the code example. /// </summary> /// <param name="service">An initialized Dfa Reporting service object /// </param> public override void Run(DfareportingService service) { long profileId = long.Parse(_T("INSERT_USER_PROFILE_ID_HERE")); String advertiserName = _T("INSERT_ADVERTISER_NAME_HERE"); // [START create_advertiser] MOE:strip_line // Create the advertiser structure. Advertiser advertiser = new Advertiser(); advertiser.Name = advertiserName; advertiser.Status = "APPROVED"; // [END create_advertiser] MOE:strip_line // [START insert_advertiser] MOE:strip_line // Create the advertiser. Advertiser result = service.Advertisers.Insert(advertiser, profileId).Execute(); // [END insert_advertiser] MOE:strip_line // Display the advertiser ID. Console.WriteLine("Advertiser with ID {0} was created.", result.Id); }
/// <summary> /// Run the code example. /// </summary> /// <param name="service">An initialized Dfa Reporting service object /// </param> public override void Run(DfareportingService service) { long advertiserId = long.Parse(_T("INSERT_ADVERTISER_ID_HERE")); long profileId = long.Parse(_T("INSERT_USER_PROFILE_ID_HERE")); String landingPageName = _T("INSERT_LANDING_PAGE_NAME_HERE"); String landingPageUrl = _T("INSERT_LANDING_PAGE_URL_HERE"); // Create the landing page structure. LandingPage landingPage = new LandingPage(); landingPage.AdvertiserId = advertiserId; landingPage.Archived = false; landingPage.Name = landingPageName; landingPage.Url = landingPageUrl; // Create the landing page. LandingPage result = service.AdvertiserLandingPages.Insert(landingPage, profileId).Execute(); // Display the landing page ID. Console.WriteLine("Advertiser landing page with ID {0} and name \"{1}\" was created.", result.Id, result.Name); }
private static void CreateAndRunFloodlightReport(DfareportingService service, long userProfileId) { DimensionValueList floodlightConfigIds = new GetDimensionValuesHelper(service).Query( "dfa:floodlightConfigId", userProfileId, StartDate, EndDate, MaxListPageSize); if (floodlightConfigIds.Items.Count > 0) { // Get a Floodlight Config ID, so we can run the rest of the samples. DimensionValue floodlightConfigId = floodlightConfigIds.Items[0]; Report floodlightReport = new CreateFloodlightReportHelper(service).Insert( userProfileId, floodlightConfigId, StartDate, EndDate); File file = new GenerateReportFileHelper(service).Run(userProfileId, floodlightReport, false); if (file != null) { // If the report file generation did not fail, display results. new DownloadReportFileHelper(service).Run(file); } } }
/// <summary> /// Run the code example. /// </summary> /// <param name="service">An initialized Dfa Reporting service object /// </param> public override void Run(DfareportingService service) { long advertiserId = long.Parse(_T("INSERT_ADVERTISER_ID_HERE")); long profileId = long.Parse(_T("INSERT_USER_PROFILE_ID_HERE")); String campaignName = _T("INSERT_CAMPAIGN_NAME_HERE"); // [START create_campaign] MOE:strip_line // Locate an advertiser landing page to use as a default. LandingPage defaultLandingPage = getAdvertiserLandingPage(service, profileId, advertiserId); // Create the campaign structure. Campaign campaign = new Campaign(); campaign.Name = campaignName; campaign.AdvertiserId = advertiserId; campaign.Archived = false; campaign.DefaultLandingPageId = defaultLandingPage.Id; // Set the campaign start date. This example uses today's date. campaign.StartDate = DfaReportingDateConverterUtil.convertToDateString(DateTime.Now); // Set the campaign end date. This example uses one month from today's date. campaign.EndDate = DfaReportingDateConverterUtil.convertToDateString(DateTime.Now.AddMonths(1)); // [END create_campaign] MOE:strip_line // [START insert_campaign] MOE:strip_line // Insert the campaign. Campaign result = service.Campaigns.Insert(campaign, profileId).Execute(); // [END insert_campaign] MOE:strip_line // Display the new campaign ID. Console.WriteLine("Campaign with ID {0} was created.", result.Id); }
private async Task Run() { UserCredential credential; using (var stream = new System.IO.FileStream("client_secrets.json", System.IO.FileMode.Open, System.IO.FileAccess.Read)) { credential = await GoogleWebAuthorizationBroker.AuthorizeAsync( GoogleClientSecrets.Load(stream).Secrets, scopes, "dfa-user", CancellationToken.None, new FileDataStore("DfaReporting.Sample")); } // Create the service. var service = new DfareportingService(new BaseClientService.Initializer { HttpClientInitializer = credential, ApplicationName = "DFA API Sample", }); // Choose a user profile ID to use in the following samples. var userProfileId = GetUserProfileId(service); if (!userProfileId.HasValue) { return; } // Create and run a standard report. CreateAndRunStandardReport(service, userProfileId.Value); // Create and run a Floodlight report. CreateAndRunFloodlightReport(service, userProfileId.Value); // List all of the Reports you have access to. new GetAllReportsHelper(service).List(userProfileId.Value, MaxReportPageSize); }
/// <summary> /// Run the code example. /// </summary> /// <param name="service">An initialized Dfa Reporting service object /// </param> public override void Run(DfareportingService service) { long campaignId = long.Parse(_T("ENTER_CAMPAIGN_ID_HERE")); long placementId = long.Parse(_T("ENTER_PLACEMENT_ID_HERE")); long profileId = long.Parse(_T("INSERT_USER_PROFILE_ID_HERE")); // Generate the placement activity tags. PlacementsResource.GeneratetagsRequest request = service.Placements.Generatetags(profileId); request.CampaignId = campaignId; request.TagFormats = PlacementsResource.GeneratetagsRequest.TagFormatsEnum.PLACEMENTTAGIFRAMEJAVASCRIPT; request.PlacementIds = placementId.ToString(); PlacementsGenerateTagsResponse response = request.Execute(); // Display the placement activity tags. foreach (PlacementTag tag in response.PlacementTags) { foreach (TagData tagData in tag.TagDatas) { Console.WriteLine("{0}:\n", tagData.Format); if (tagData.ImpressionTag != null) { Console.WriteLine(tagData.ImpressionTag); } if (tagData.ClickTag != null) { Console.WriteLine(tagData.ClickTag); } Console.WriteLine(); } } }
/// <summary> /// Run the code example. /// </summary> /// <param name="service">An initialized Dfa Reporting service object /// </param> public override void Run(DfareportingService service) { long advertiserId = long.Parse(_T("INSERT_ADVERTISER_ID_HERE")); long sizeId = long.Parse(_T("INSERT_SIZE_ID_HERE")); long profileId = long.Parse(_T("INSERT_USER_PROFILE_ID_HERE")); string imageUrl = _T("INSERT_IMAGE_URL_HERE"); Creative creative = new Creative(); creative.AdvertiserId = advertiserId; creative.Name = "Test redirect creative"; creative.RedirectUrl = imageUrl; creative.Size = new Size() { Id = sizeId }; creative.Type = "REDIRECT"; Creative result = service.Creatives.Insert(creative, profileId).Execute(); // Display the new creative ID. Console.WriteLine("Redirect creative with ID {0} was created.", result.Id); }
/// <summary> /// Run the code example. /// </summary> /// <param name="service">An initialized Dfa Reporting service object /// </param> public override void Run(DfareportingService service) { long profileId = long.Parse(_T("INSERT_PROFILE_ID_HERE")); CreativeFieldsListResponse fields; String nextPageToken = null; do { // Create and execute the creative field values list request. CreativeFieldsResource.ListRequest request = service.CreativeFields.List(profileId); request.PageToken = nextPageToken; fields = request.Execute(); foreach (CreativeField field in fields.CreativeFields) { Console.WriteLine("Found creative field with ID {0} and name \"{1}\".", field.Id, field.Name); } // Update the next page token. nextPageToken = fields.NextPageToken; } while (fields.CreativeFields.Any() && !String.IsNullOrEmpty(nextPageToken)); }
/// <summary> /// Waits for a report file to generate by polling for its status using exponential /// backoff. In the worst case, there will be 10 attempts to determine if the report is no /// longer processing. /// </summary> /// <param name="service">DfaReporting service object used to run the requests.</param> /// <param name="userProfileId"> /// The ID number of the DFA user profile to run this request as. /// </param> /// <param name="file">The report file to poll the status of.</param> /// <returns>The report file object, either once it is no longer processing or /// once too much time has passed.</returns> private static File WaitForReportRunCompletion(DfareportingService service, long userProfileId, File file) { ExponentialBackOff backOff = new ExponentialBackOff(); TimeSpan interval; file = service.Reports.Files.Get(userProfileId, file.ReportId.Value, file.Id.Value).Execute(); for (int i = 1; i <= backOff.MaxNumOfRetries; i++) { if (!file.Status.Equals("PROCESSING")) { break; } interval = backOff.GetNextBackOff(i); Console.WriteLine("Polling again in {0} seconds.", interval); Thread.Sleep(interval); file = service.Reports.Files.Get(userProfileId, file.ReportId.Value, file.Id.Value).Execute(); } return(file); }
/// <summary> /// Retrieves a list of sites, possibly filtered. This method supports paging. /// Documentation https://developers.google.com/dfareporting/v2.7/reference/sites/list /// Generation Note: This does not always build corectly. Google needs to standardise things I need to figuer out which ones are wrong. /// </summary> /// <param name="service">Authenticated Dfareporting service.</param> /// <param name="profileId">User profile ID associated with this request.</param> /// <param name="optional">Optional paramaters.</param> /// <returns>SitesListResponseResponse</returns> public static SitesListResponse List(DfareportingService service, string profileId, SitesListOptionalParms optional = null) { try { // Initial validation. if (service == null) throw new ArgumentNullException("service"); if (profileId == null) throw new ArgumentNullException(profileId); // Building the initial request. var request = service.Sites.List(profileId); // Applying optional parameters to the request. request = (SitesResource.ListRequest)SampleHelpers.ApplyOptionalParms(request, optional); // Requesting data. return request.Execute(); } catch (Exception ex) { throw new Exception("Request Sites.List failed.", ex); } }
/// <summary> /// Instantiate a helper for retrieving dimension values. /// </summary> /// <param name="service">DfaReporting service object used to run the requests.</param> public GetDimensionValuesHelper(DfareportingService service) { this.service = service; }
/// <summary>Instantiate a helper for generating a new file for a report.</summary> /// <param name="service">DfaReporting service object used to run the requests.</param> public GenerateReportFileHelper(DfareportingService service) { this.service = service; }
/// <summary> /// Run the code example. /// </summary> /// <param name="service">An initialized Dfa Reporting service object /// </param> public override void Run(DfareportingService service) { long encryptionEntityId = long.Parse(_T("INSERT_ENCRYPTION_ENTITY_TYPE")); long floodlightActivityId = long.Parse(_T("INSERT_FLOODLIGHT_ACTIVITY_ID_HERE")); long profileId = long.Parse(_T("INSERT_USER_PROFILE_ID_HERE")); string conversionUserId = _T("INSERT_CONVERSION_USER_ID_HERE"); string encryptionEntityType = _T("INSERT_ENCRYPTION_ENTITY_TYPE_HERE"); string encryptionSource = _T("INSERT_ENCRYPTION_SOURCE_HERE"); // Generate a timestamp in milliseconds since Unix epoch. TimeSpan timeSpan = DateTime.UtcNow - new DateTime(1970, 1, 1); long currentTimeInMilliseconds = (long)timeSpan.TotalMilliseconds; // Find the Floodlight configuration ID based on the provided activity ID. FloodlightActivity floodlightActivity = service.FloodlightActivities.Get(profileId, floodlightActivityId).Execute(); long floodlightConfigurationId = (long)floodlightActivity.FloodlightConfigurationId; // Create the conversion. Conversion conversion = new Conversion(); conversion.EncryptedUserId = conversionUserId; conversion.FloodlightActivityId = floodlightActivityId; conversion.FloodlightConfigurationId = floodlightConfigurationId; conversion.Ordinal = currentTimeInMilliseconds.ToString(); conversion.TimestampMicros = currentTimeInMilliseconds * 1000; // Create the encryption info. EncryptionInfo encryptionInfo = new EncryptionInfo(); encryptionInfo.EncryptionEntityId = encryptionEntityId; encryptionInfo.EncryptionEntityType = encryptionEntityType; encryptionInfo.EncryptionSource = encryptionSource; // Insert the conversion. ConversionsBatchInsertRequest request = new ConversionsBatchInsertRequest(); request.Conversions = new List <Conversion>() { conversion }; request.EncryptionInfo = encryptionInfo; ConversionsBatchInsertResponse response = service.Conversions.Batchinsert(request, profileId).Execute(); // Handle the batchinsert response. if (!response.HasFailures.Value) { Console.WriteLine("Successfully inserted conversion for encrypted user ID {0}.", conversionUserId); } else { Console.WriteLine("Error(s) inserting conversion for encrypted user ID {0}:", conversionUserId); ConversionStatus status = response.Status[0]; foreach (ConversionError error in status.Errors) { Console.WriteLine("\t[{0}]: {1}", error.Code, error.Message); } } }
/// <summary> /// Run the code example. /// </summary> /// <param name="service">An initialized Dfa Reporting service object /// </param> public override void Run(DfareportingService service) { long advertiserId = long.Parse(_T("INSERT_ADVERTISER_ID_HERE")); long sizeId = long.Parse(_T("INSERT_SIZE_ID_HERE")); long profileId = long.Parse(_T("INSERT_USER_PROFILE_ID_HERE")); string pathToImageAssetFile = _T("INSERT_PATH_TO_IMAGE_ASSET_FILE_HERE"); string pathToImageAsset2File = _T("INSERT_PATH_TO_IMAGE_ASSET_FILE_HERE"); Creative creative = new Creative(); creative.AdvertiserId = advertiserId; creative.AutoAdvanceImages = true; creative.Name = "Test display image gallery creative"; creative.Size = new Size() { Id = sizeId }; creative.Type = "DISPLAY_IMAGE_GALLERY"; // Upload the first image asset. CreativeAssetUtils assetUtils = new CreativeAssetUtils(service, profileId, advertiserId); CreativeAssetId imageAsset1Id = assetUtils.uploadAsset(pathToImageAssetFile, "HTML_IMAGE").AssetIdentifier; CreativeAsset imageAsset1 = new CreativeAsset(); imageAsset1.AssetIdentifier = imageAsset1Id; imageAsset1.Role = "PRIMARY"; // Upload the second image asset. CreativeAssetId imageAsset2Id = assetUtils.uploadAsset(pathToImageAsset2File, "HTML_IMAGE").AssetIdentifier; CreativeAsset imageAsset2 = new CreativeAsset(); imageAsset2.AssetIdentifier = imageAsset2Id; imageAsset2.Role = "PRIMARY"; // Add the creative assets. creative.CreativeAssets = new List <CreativeAsset>() { imageAsset1, imageAsset2 }; // Create a click tag for the first image asset. ClickTag clickTag1 = new ClickTag(); clickTag1.Name = imageAsset1Id.Name; clickTag1.EventName = imageAsset1Id.Name; // Create a click tag for the second image asset. ClickTag clickTag2 = new ClickTag(); clickTag2.Name = imageAsset2Id.Name; clickTag2.EventName = imageAsset2Id.Name; // Add the click tags. creative.ClickTags = new List <ClickTag>() { clickTag1, clickTag2 }; Creative result = service.Creatives.Insert(creative, profileId).Execute(); // Display the new creative ID. Console.WriteLine("Display image gallery creative with ID {0} was created.", result.Id); }
/// <summary> /// Run the code example. /// </summary> /// <param name="service">An initialized Dfa Reporting service object /// </param> public override void Run(DfareportingService service) { long advertiserId = long.Parse(_T("INSERT_ADVERTISER_ID_HERE")); long sizeId = long.Parse(_T("INSERT_SIZE_ID_HERE")); long profileId = long.Parse(_T("INSERT_USER_PROFILE_ID_HERE")); string pathToHtml5AssetFile = _T("INSERT_PATH_TO_HTML5_ASSET_FILE_HERE"); string pathToImageAssetFile = _T("INSERT_PATH_TO_IMAGE_ASSET_FILE_HERE"); Creative creative = new Creative(); creative.AdvertiserId = advertiserId; creative.Name = "Test HTML5 display creative"; creative.Size = new Size() { Id = sizeId }; creative.Type = "DISPLAY"; // Upload the HTML5 asset. CreativeAssetUtils assetUtils = new CreativeAssetUtils(service, profileId, advertiserId); CreativeAssetId html5AssetId = assetUtils.uploadAsset(pathToHtml5AssetFile, "HTML").AssetIdentifier; CreativeAsset html5Asset = new CreativeAsset(); html5Asset.AssetIdentifier = html5AssetId; html5Asset.Role = "PRIMARY"; // Upload the backup image asset. CreativeAssetId imageAssetId = assetUtils.uploadAsset(pathToImageAssetFile, "HTML_IMAGE").AssetIdentifier; CreativeAsset imageAsset = new CreativeAsset(); imageAsset.AssetIdentifier = imageAssetId; imageAsset.Role = "BACKUP_IMAGE"; // Add the creative assets. creative.CreativeAssets = new List <CreativeAsset>() { html5Asset, imageAsset }; // Configure the bacup image. creative.BackupImageClickThroughUrl = "https://www.google.com"; creative.BackupImageReportingLabel = "backup"; creative.BackupImageTargetWindow = new TargetWindow() { TargetWindowOption = "NEW_WINDOW" }; // Add a click tag. ClickTag clickTag = new ClickTag(); clickTag.Name = "clickTag"; clickTag.EventName = "exit"; clickTag.Value = "https://www.google.com"; creative.ClickTags = new List <ClickTag>() { clickTag }; Creative result = service.Creatives.Insert(creative, profileId).Execute(); // Display the new creative ID. Console.WriteLine("HTML5 display creative with ID {0} was created.", result.Id); }
public CreativeAssetUtils(DfareportingService service, long profileId, long advertiserId) { AdvertiserId = advertiserId; ProfileId = profileId; Service = service; }
/// <summary> /// Run the code example. /// </summary> /// <param name="service">A Dfa Reporting service instance.</param> public abstract void Run(DfareportingService service);
/// <summary> /// Run the code example. /// </summary> /// <param name="service">An initialized Dfa Reporting service object /// </param> public override void Run(DfareportingService service) { long campaignId = long.Parse(_T("INSERT_CAMPAIGN_ID_HERE")); long creativeId = long.Parse(_T("INSERT_CREATIVE_ID_HERE")); long placementId = long.Parse(_T("INSERT_PLACEMENT_ID_HERE")); long profileId = long.Parse(_T("INSERT_PROFILE_ID_HERE")); String adName = _T("INSERT_AD_NAME_HERE"); // Retrieve the campaign. Campaign campaign = service.Campaigns.Get(profileId, campaignId).Execute(); // Create a click-through URL. ClickThroughUrl clickThroughUrl = new ClickThroughUrl(); clickThroughUrl.DefaultLandingPage = true; // Create a creative assignment. CreativeAssignment creativeAssignment = new CreativeAssignment(); creativeAssignment.Active = true; creativeAssignment.CreativeId = creativeId; creativeAssignment.ClickThroughUrl = clickThroughUrl; // Create a placement assignment. PlacementAssignment placementAssignment = new PlacementAssignment(); placementAssignment.Active = true; placementAssignment.PlacementId = placementId; // Create a creative rotation. CreativeRotation creativeRotation = new CreativeRotation(); creativeRotation.CreativeAssignments = new List <CreativeAssignment>() { creativeAssignment }; // Create a delivery schedule. DeliverySchedule deliverySchedule = new DeliverySchedule(); deliverySchedule.ImpressionRatio = 1; deliverySchedule.Priority = "AD_PRIORITY_01"; DateTime startDate = DateTime.Now; DateTime endDate = Convert.ToDateTime(campaign.EndDate); // Create a rotation group. Ad rotationGroup = new Ad(); rotationGroup.Active = true; rotationGroup.CampaignId = campaignId; rotationGroup.CreativeRotation = creativeRotation; rotationGroup.DeliverySchedule = deliverySchedule; rotationGroup.StartTime = startDate; rotationGroup.EndTime = endDate; rotationGroup.Name = adName; rotationGroup.PlacementAssignments = new List <PlacementAssignment>() { placementAssignment }; rotationGroup.Type = "AD_SERVING_STANDARD_AD"; // Insert the rotation group. Ad result = service.Ads.Insert(rotationGroup, profileId).Execute(); // Display the new ad ID. Console.WriteLine("Ad with ID {0} was created.", result.Id); }