WP Remix
Analytics for a New Generation

C# Code Example - Retrieving reports using NuConomy SOAP API

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NuConomy.Samples.RunningReportsUsingNuConomyAPI.ws.nuconomy.com;

namespace NuConomy.Samples.RunningReportsUsingNuConomyAPI
{
    class Program
    {
        static void Main(string[] args)
        {
            // Add a web referrence to https://ws.nuconomy.com/v0.6/ReportsGenerator.asmx

            RunActivityStatisticsReport();

            Console.WriteLine("*************************************************");
            Console.ReadKey();

            RunMeasuresStatisticsReport();

            Console.WriteLine("*************************************************");
            Console.ReadKey();

            RunReferrersByActivityReport();

            Console.WriteLine("*************************************************");
            Console.ReadKey();

            RunTopContentByActivityReport();

            Console.WriteLine("*************************************************");
            Console.ReadKey();

            RunTopExternalSearchTermsReport();

            Console.WriteLine("*************************************************");
            Console.ReadKey();

            RunTopCountriesByActivityReport();

            Console.WriteLine("*************************************************");
            Console.ReadKey();
        }

        /// 
        /// Get the activities on your site for a specific date range
        /// 
        private static void RunActivityStatisticsReport()
        {
            // Create the report generator object
            ws.nuconomy.com.ReportsGenerator nuconomyService = new ReportsGenerator();

            // Create the object that will hold all of the report parameters
            ws.nuconomy.com.ActivityStatisticsReportBuilder activityStatisticsParameters =
                new ActivityStatisticsReportBuilder();
            activityStatisticsParameters.FromToStart = new DateTime(2008, 9, 1); // The from date
            activityStatisticsParameters.FromToEnd = new DateTime(2008, 9, 7); // The to date
            activityStatisticsParameters.Measure = "Events"; // We want to get the total events that occured for each activity
            activityStatisticsParameters.SortOrder = SortDirection.Top;

            // Execute the report and get an array containing all the results
            // Remember that you need to your server side token and not the one you use on the client side
            // JavaScript code.
            ActivityStatisticsReportRow[] results = nuconomyService.ExecuteActivityStatisticsReport("Your Project Token", 100, activityStatisticsParameters);

            // Go over all the results
            foreach (ActivityStatisticsReportRow currentResult in results)
            {
                Console.WriteLine("{0} {1} occured in the site. a change of {2} {3}", currentResult.Value, currentResult.Name, currentResult.Change, currentResult.Name );
            }
        }

        /// 
        /// Get the mreasures (uniques, visits, etc) on your site for a specific date range
        /// 
        private static void RunMeasuresStatisticsReport()
        {
            // Create the report generator object
            ws.nuconomy.com.ReportsGenerator nuconomyService = new ReportsGenerator();

            // Create the object that will hold all of the report parameters
            ws.nuconomy.com.MeasureStatisticsReportBuilder measuresStatisticsParameters =
                new MeasureStatisticsReportBuilder();
            measuresStatisticsParameters.FromToStart = new DateTime(2008, 9, 1); // The from date
            measuresStatisticsParameters.FromToEnd = new DateTime(2008, 9, 7); // The to date
            measuresStatisticsParameters.Measure = "Events"; // We want to get the total events that occured for each activity
            measuresStatisticsParameters.SortOrder = SortDirection.Top;

            // Execute the report and get an array containing all the results
            // Remember that you need to your server side token and not the one you use on the client side
            // JavaScript code.
            MeasureStatisticsReportRow[] results = nuconomyService.ExecuteMeasureStatisticsReport("Your Project Token", 100, measuresStatisticsParameters);

            // Go over all the results
            foreach (MeasureStatisticsReportRow currentResult in results)
            {
                Console.WriteLine("{0} {1} occured in the site. a change of {2} {3}", currentResult.NewValue, currentResult.Name, currentResult.Diffrence, currentResult.Name);
            }
        }

        /// 
        /// Get the top contributing referrers by activity
        /// 
        private static void RunReferrersByActivityReport()
        {
            // Create the report generator object
            ws.nuconomy.com.ReportsGenerator nuconomyService = new ReportsGenerator();

            // Create the object that will hold all of the report parameters
            ws.nuconomy.com.SiteActivityByReferrersReportBuilder referresParameters = new SiteActivityByReferrersReportBuilder();

            // Add all the id for all the activities you want to get in results
            referresParameters.ActivityId = new string[] { "1" };

            referresParameters.FromToStart = new DateTime(2008, 9, 1); // The from date
            referresParameters.FromToEnd = new DateTime(2008, 9, 7); // The to date
            referresParameters.Measure = "Events"; // We want to get the total events that occured for each activity
            referresParameters.SortOrder = SortDirection.Top;

            // Execute the report and get an array containing all the results
            // Remember that you need to your server side token and not the one you use on the client side
            // JavaScript code.
            SiteActivityByReferrersReportRow[] results = nuconomyService.ExecuteSiteActivityByReferrersReport("Your Project Token", 100, referresParameters);

            // Go over all the results
            foreach (SiteActivityByReferrersReportRow currentReferrer in results)
            {
                Console.WriteLine("{0} contributed {1} of the specific activity", currentReferrer.Referrer, currentReferrer.Value);
            }
        }

        /// 
        /// Get the top content by activity
        /// 
        private static void RunTopContentByActivityReport()
        {
            // Create the report generator object
            ws.nuconomy.com.ReportsGenerator nuconomyService = new ReportsGenerator();

            // Create the object that will hold all of the report parameters
            ws.nuconomy.com.ContentByActivityReportBuilder contentParameters = new ContentByActivityReportBuilder();

            // Add all the id for all the activities you want to get in results
            contentParameters.ActivityId = new string[] { "1" };

            contentParameters.FromToStart = new DateTime(2008, 9, 1); // The from date
            contentParameters.FromToEnd = new DateTime(2008, 9, 7); // The to date
            contentParameters.Measure = "Events"; // We want to get the total events that occured for each activity
            contentParameters.SortOrder = SortDirection.Top;

            // Execute the report and get an array containing all the results
            // Remember that you need to your server side token and not the one you use on the client side
            // JavaScript code.
            ContentByActivityReportRow[] results = nuconomyService.ExecuteContentByActivityReport("Your Project Token", 100, contentParameters);

            foreach (ContentByActivityReportRow contentResult in results)
            {
                Console.WriteLine("{0} with title {1} got {2} of the specified activity", contentResult.Content, contentResult.Title, contentResult.Value);
            }
        }

        /// 
        /// Get the top contributing external search terms
        /// 
        private static void RunTopExternalSearchTermsReport()
        {
            // Create the report generator object
            ws.nuconomy.com.ReportsGenerator nuconomyService = new ReportsGenerator();

            // Create the object that will hold all of the report parameters
            ws.nuconomy.com.ExternalSearchTermsReportBuilder searchTermsParameters = new ExternalSearchTermsReportBuilder();

            // Add all the id for all the activities you want to get in results
            searchTermsParameters.ActivityId = new string[] { "1" };

            searchTermsParameters.FromToStart = new DateTime(2008, 9, 1); // The from date
            searchTermsParameters.FromToEnd = new DateTime(2008, 9, 7); // The to date
            searchTermsParameters.Measure = "Events"; // We want to get the total events that occured for each activity
            searchTermsParameters.SortOrder = SortDirection.Top;

            // Execute the report and get an array containing all the results
            // Remember that you need to your server side token and not the one you use on the client side
            // JavaScript code.
            ExternalSearchTermsReportRow[] results = nuconomyService.ExecuteExternalSearchTermsReport("Your Project Token", 100, searchTermsParameters);

            foreach (ExternalSearchTermsReportRow searchTermResult in results)
            {
                Console.WriteLine("The search term {0} contributed {1} of the specified activity", searchTermResult.Term, searchTermResult.Value);
            }
        }

        /// 
        /// Get the top contributing countries (GEO) to your site
        /// 
        private static void RunTopCountriesByActivityReport()
        {
            // Create the report generator object
            ws.nuconomy.com.ReportsGenerator nuconomyService = new ReportsGenerator();

            // Create the object that will hold all of the report parameters
            ws.nuconomy.com.TopCountriesReportBuilder countriesParameters = new TopCountriesReportBuilder();

            // Add all the id for all the activities you want to get in results
            countriesParameters.ActivityId = new string[] { "1" };

            countriesParameters.FromToStart = new DateTime(2008, 9, 1); // The from date
            countriesParameters.FromToEnd = new DateTime(2008, 9, 7); // The to date
            countriesParameters.Measure = "Events"; // We want to get the total events that occured for each activity
            countriesParameters.SortOrder = SortDirection.Top;

            // Execute the report and get an array containing all the results
            // Remember that you need to your server side token and not the one you use on the client side
            // JavaScript code.
            TopCountriesReportRow[] results = nuconomyService.ExecuteTopCountriesReport("Your Project Token", 100, countriesParameters);

            foreach (TopCountriesReportRow countryResult in results)
            {
                Console.WriteLine("The country {0} contributed {1} of the specified activity", countryResult.CountryName, countryResult.Value);
            }
        }
    }
}