Пример #1
0
 public Management.Data.CustomMetric GetCustomMetricByName(string name)
 {
     try
     {
         if (CustomMetrics == null)
         {
             GetCustomMetrics();
         }
         var dimension = (from x in CustomMetrics where x.Name == name select x).FirstOrDefault();
         if (dimension != null)
         {
             Management.Data.CustomMetric d = new Management.Data.CustomMetric()
             {
                 Id = dimension.Id, Index = dimension.Index, Name = dimension.Name
             };
             return(d);
         }
         else
         {
             return(null);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
     return(null);
 }
Пример #2
0
 public Management.Data.CustomMetric GetCustomMetricById(string id)
 {
     Google.Apis.Analytics.v3.ManagementResource.CustomMetricsResource.GetRequest request = analyticsService.Management.CustomMetrics.Get(DefaultAccount.Id, DefaultProfile.WebPropertyId, id);
     try
     {
         var dimension = request.Execute();
         Management.Data.CustomMetric d = new Management.Data.CustomMetric()
         {
             Id = dimension.Id, Index = dimension.Index, Name = dimension.Name
         };
         return(d);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
     return(null);
 }
Пример #3
0
 public Management.Data.CustomMetric CreateCustomMetric(string name, bool isActive)
 {
     Google.Apis.Analytics.v3.Data.CustomMetric dimension = new Google.Apis.Analytics.v3.Data.CustomMetric()
     {
         Active = isActive, AccountId = DefaultAccount.Id, Name = name, Scope = "HIT", WebPropertyId = DefaultProfile.WebPropertyId
     };
     Google.Apis.Analytics.v3.ManagementResource.CustomMetricsResource.InsertRequest request = analyticsService.Management.CustomMetrics.Insert(dimension, DefaultAccount.Id, DefaultProfile.WebPropertyId);
     try
     {
         dimension = request.Execute();
         CustomMetrics.Add(dimension);
         Management.Data.CustomMetric d = new Management.Data.CustomMetric()
         {
             Id = dimension.Id, Index = dimension.Index, Name = dimension.Name
         };
         return(d);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
     return(null);
 }