Ejemplo n.º 1
0
        /// <summary>
        /// Gets the seed keywords from a Search Query Report.
        /// </summary>
        /// <param name="user">The user for which reports are run.</param>
        /// <param name="campaignId">ID of the campaign for which we are generating
        ///  keyword ideas.</param>
        /// <returns>A list of seed keywords from SQR, to be used for getting
        /// further keyword ideas.</returns>
        private List <SeedKeyword> GetSeedKeywordsFromQueryReport(AdWordsUser user, long campaignId)
        {
            string query = string.Format("Select Query, MatchTypeWithVariant, Clicks, Impressions " +
                                         "from SEARCH_QUERY_PERFORMANCE_REPORT where CampaignId = {0} during LAST_MONTH",
                                         campaignId);

            AdWordsAppConfig config = (AdWordsAppConfig)user.Config;

            config.SkipReportHeader  = true;
            config.SkipReportSummary = true;

            ReportUtilities utilities = new ReportUtilities(user, query, DownloadFormat.CSV.ToString());
            ReportResponse  response  = utilities.GetResponse();

            List <SeedKeyword> retval = new List <SeedKeyword>();

            using (response) {
                byte[] data   = response.Download();
                string report = Encoding.UTF8.GetString(data);

                CsvFile csvFile = new CsvFile();
                csvFile.ReadFromString(report, true);

                foreach (string[] row in csvFile.Records)
                {
                    row[1] = row[1].Replace("(close variant)", "").Trim();
                    SeedKeyword sqrKeyword = new SeedKeyword()
                    {
                        Keyword = new LocalKeyword()
                        {
                            Text      = row[0],
                            MatchType = (KeywordMatchType)Enum.Parse(typeof(KeywordMatchType), row[1], true)
                        },
                        Stat = new Stat()
                        {
                            Clicks      = long.Parse(row[2]),
                            Impressions = long.Parse(row[3])
                        },
                        Source = GetNewKeywords.Source.SQR
                    };
                    retval.Add(sqrKeyword);
                }
            }

            LimitResults(retval, Settings.SQR_MAX_RESULTS);
            return(retval);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Downloads the campaign performance report.
        /// </summary>
        /// <param name="user">The user for which the report is run..</param>
        /// <param name="startDate">The start date in yyyyMMdd format.</param>
        /// <param name="endDate">The end date in yyyyMMdd format.</param>
        /// <returns>The campaign performance report, as a CSV file.</returns>
        private CsvFile DownloadCampaignPerformanceReport(AdWordsUser user, string startDate,
                                                          string endDate)
        {
            string query = string.Format("Select {0} from CAMPAIGN_PERFORMANCE_REPORT DURING {1}, {2}",
                                         string.Join(", ", CAMPAIGN_PERFORMANCE_COLUMNS), startDate, endDate);

            AdWordsAppConfig appConfig = user.Config as AdWordsAppConfig;

            appConfig.SkipReportHeader  = true;
            appConfig.SkipReportSummary = true;

            ReportUtilities reportUtilities = new ReportUtilities(user, query,
                                                                  DownloadFormat.CSV.ToString());

            using (ReportResponse response = reportUtilities.GetResponse()) {
                string  reportContents = Encoding.UTF8.GetString(response.Download());
                CsvFile csvFile        = new CsvFile();
                csvFile.ReadFromString(reportContents, true);
                return(csvFile);
            }
        }
Ejemplo n.º 3
0
        public void TestDownload()
        {
            ReportResponse response = new ReportResponse(webResponse);

            this.AssertContentsAreEqual(response.Download());
        }