예제 #1
0
 public ProfileModel(AnalyticsProfile profile)
 {
     Id         = profile.Id;
     Name       = profile.Name;
     Currency   = profile.Currency;
     Timezone   = profile.Timezone;
     WebsiteUrl = AddHttp(profile.WebsiteUrl);
     Type       = profile.Type;
     Created    = TimeUtils.ToIso8601(profile.Created);
     Updated    = TimeUtils.ToIso8601(profile.Updated);
 }
예제 #2
0
        public static void Main(string[] args)
        {
            var builder             = new ConfigurationBuilder().AddJsonFile("gasettings.json");
            var config              = builder.Build();
            var viewId              = Convert.ToUInt32(config["profile:view_id"]);
            var serviceAccountEmail = config["profile:service_account_email"];
            var applicationName     = config["profile:application_name"];
            var keyFilePath         = Directory.GetCurrentDirectory() + "\\" + config["profile:key_file_name"];

            var profile         = new AnalyticsProfile(serviceAccountEmail, keyFilePath, applicationName);
            var googleAnalytics = new AnalyticsContext(profile);
            var records         = googleAnalytics.Records
                                  // View Id
                                  .Where(x => x.ViewId == viewId)
                                  // Start Date, End Date
                                  .Where(x => x.RecordDate == DateTime.Today.AddDays(-1))
                                  // Include Dimensions
                                  .Include(x => x.Source)
                                  .Include(x => x.Medium)
                                  // Include Metrics
                                  .Include(x => x.Pageviews)
                                  .Include(x => x.Sessions)
                                  .Include(x => x.SessionDuration)
                                  // Filters
                                  .Where(x => x.Country == "India" && x.Medium == new Regex("organic"))
                                  .Where(x => x.Source.Contains("a") && !x.Source.Contains("x"))
                                  .Where(x => x.SessionDuration > TimeSpan.FromMinutes(1))
                                  // Sort
                                  .OrderByDescending(x => x.SessionDuration)
                                  .ThenBy(x => x.Source)
                                  // Skip 1 record
                                  .Skip(1)
                                  // Take only 5 records
                                  .Take(5);

            foreach (var record in records)
            {
                Console.WriteLine(record.ToStringRepresentation());
            }

            Task.Run(async() =>
            {
                var list = await records.ToListAsync();
                foreach (var item in list)
                {
                    Console.WriteLine(item.ToStringRepresentation());
                }
            }).Wait();

            Console.ReadLine();
        }
예제 #3
0
 public Profile(AnalyticsProfile profile)
 {
     Id                    = profile.Id;
     AccountId             = profile.AccountId;
     WebPropertyId         = profile.WebPropertyId;
     InternalWebPropertyId = profile.InternalWebPropertyId;
     Name                  = profile.Name;
     Currency              = profile.Currency;
     Timezone              = profile.Timezone;
     WebsiteUrl            = profile.WebsiteUrl;
     Type                  = profile.Type;
     Created               = profile.Created;
     Updated               = profile.Updated;
 }
예제 #4
0
 /// <summary>
 /// Gets the realtime data from the specified profile and options.
 /// </summary>
 /// <param name="profile">The Analytics profile to gather realtime data from.</param>
 /// <param name="options">The options specifying the query.</param>
 public string GetRealtimeData(AnalyticsProfile profile, AnalyticsRealtimeDataOptions options)
 {
     return(GetRealtimeData(profile.Id, options));
 }
예제 #5
0
 /// <summary>
 /// Gets the realtime data from the specified profile, metrics and dimensions.
 /// </summary>
 /// <param name="profile">The Analytics profile to gather realtime data from.</param>
 /// <param name="metrics">The metrics collection of what data to return.</param>
 /// <param name="dimensions">The dimensions collection of what data to return.</param>
 public string GetRealtimeData(AnalyticsProfile profile, AnalyticsMetricCollection metrics, AnalyticsDimensionCollection dimensions)
 {
     return(GetRealtimeData(profile.Id, metrics, dimensions));
 }
예제 #6
0
 public string GetData(AnalyticsProfile profile, DateTime startDate, DateTime endDate, AnalyticsMetricCollection metrics, AnalyticsDimensionCollection dimensions)
 {
     return(GetData(profile.Id, startDate, endDate, metrics, dimensions));
 }
예제 #7
0
 public string GetData(AnalyticsProfile profile, DateTime startDate, DateTime endDate, string[] metrics, string[] dimensions)
 {
     return(GetData(profile.Id, startDate, endDate, metrics, dimensions));
 }
 public static string GetData(this AnalyticsRawEndpoint endpoint, AnalyticsProfile profile, DateTime startDate, DateTime endDate, string[] metrics, string[] dimensions, string[] filters, string[] sort)
 {
     return(GetData(endpoint, profile.Id, startDate, endDate, metrics, dimensions, filters, sort));
 }
 public static AnalyticsDataResponse GetData(this AnalyticsEndpoint endpoint, AnalyticsProfile profile, DateTime startDate, DateTime endDate, string[] metrics, string[] dimensions, string[] filters, string[] sort)
 {
     return(AnalyticsDataResponse.ParseJson(endpoint.Service.Client.Analytics.GetData(profile, startDate, endDate, metrics, dimensions, filters, sort)));
 }
 /// <summary>
 /// Gets a view (profile) to which the user has access.
 /// </summary>
 /// <param name="accountId">Account ID to retrieve the goal for.</param>
 /// <param name="webPropertyId">Web property ID to retrieve the goal for.</param>
 /// <param name="profileId">View (Profile) ID to retrieve the goal for.</param>
 public AnalyticsProfile GetProfile(string accountId, string webPropertyId, string profileId)
 {
     return(AnalyticsProfile.ParseJson(Raw.GetProfile(accountId, webPropertyId, profileId)));
 }
 /// <summary>
 /// Gets realtime data for the specified profile and options.
 /// </summary>
 /// <param name="profile">The Analytics profile to gather realtime data from.</param>
 /// <param name="options">The options specifying the query.</param>
 public AnalyticsRealtimeDataResponse GetRealtimeData(AnalyticsProfile profile, AnalyticsRealtimeDataOptions options)
 {
     return(AnalyticsRealtimeDataResponse.ParseJson(Raw.GetRealtimeData(profile.Id, options)));
 }
 /// <summary>
 /// Gets the realtime data from the specified profile and metrics.
 /// </summary>
 /// <param name="profile">The Analytics profile to gather realtime data from.</param>
 /// <param name="metrics">The metrics collection of what data to return.</param>
 public AnalyticsRealtimeDataResponse GetRealtimeData(AnalyticsProfile profile, AnalyticsMetricCollection metrics)
 {
     return(GetRealtimeData(profile.Id, metrics));
 }
 public AnalyticsDataResponse GetData(AnalyticsProfile profile, DateTime startDate, DateTime endDate, AnalyticsMetricCollection metrics, AnalyticsDimensionCollection dimensions)
 {
     return(AnalyticsDataResponse.ParseJson(Raw.GetData(profile, startDate, endDate, metrics, dimensions)));
 }
 public AnalyticsDataResponse GetData(AnalyticsProfile profile, DateTime startDate, DateTime endDate, string[] metrics, string[] dimensions)
 {
     return(AnalyticsDataResponse.ParseJson(Raw.GetData(profile, startDate, endDate, metrics, dimensions)));
 }