Beispiel #1
0
        public static string CreateCustomDimension(AnalyticsService ga, string accountId, string webPropertyId, string dimensionName, string scope, bool active)
        {
            List<CustomDimension> customDimensions = ga.Management.CustomDimensions.List(accountId, webPropertyId).Execute().Items as List<CustomDimension>;

            if (!customDimensions.Select(c => c.Name).Contains(dimensionName))
            {
                CustomDimension body = new CustomDimension
                {
                    AccountId = accountId,
                    WebPropertyId = webPropertyId,
                    Name = dimensionName,
                    Scope = scope,
                    Active = active
                };

                ManagementResource.CustomDimensionsResource.InsertRequest request = ga.Management.CustomDimensions.Insert(body, accountId, webPropertyId);
                CustomDimension newDimension = request.Execute();

                List<CustomDimension> newDimensions = ga.Management.CustomDimensions.List(accountId, webPropertyId).Execute().Items as List<CustomDimension>;
                if (newDimensions.Select(d => d.Id).Contains(newDimension.Id)) return "Success: Custom Dimension Added";
                else return "Failure: Unknown";
            } else
            {
                return "Custom Dimension Already Exists";
            }
        }
 /// <summary>Snippet for GetCustomDimension</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void GetCustomDimensionResourceNames()
 {
     // Create client
     AnalyticsAdminServiceClient analyticsAdminServiceClient = AnalyticsAdminServiceClient.Create();
     // Initialize request argument(s)
     CustomDimensionName name = CustomDimensionName.FromProperty("[PROPERTY]");
     // Make the request
     CustomDimension response = analyticsAdminServiceClient.GetCustomDimension(name);
 }
Beispiel #3
0
 /// <summary>Snippet for GetCustomDimension</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void GetCustomDimension()
 {
     // Create client
     AnalyticsAdminServiceClient analyticsAdminServiceClient = AnalyticsAdminServiceClient.Create();
     // Initialize request argument(s)
     string name = "properties/[PROPERTY]/customDimensions";
     // Make the request
     CustomDimension response = analyticsAdminServiceClient.GetCustomDimension(name);
 }
Beispiel #4
0
 /// <summary>Snippet for UpdateCustomDimension</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void UpdateCustomDimension()
 {
     // Create client
     AnalyticsAdminServiceClient analyticsAdminServiceClient = AnalyticsAdminServiceClient.Create();
     // Initialize request argument(s)
     CustomDimension customDimension = new CustomDimension();
     FieldMask       updateMask      = new FieldMask();
     // Make the request
     CustomDimension response = analyticsAdminServiceClient.UpdateCustomDimension(customDimension, updateMask);
 }
Beispiel #5
0
 /// <summary>Snippet for CreateCustomDimension</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void CreateCustomDimensionResourceNames()
 {
     // Create client
     AnalyticsAdminServiceClient analyticsAdminServiceClient = AnalyticsAdminServiceClient.Create();
     // Initialize request argument(s)
     PropertyName    parent          = PropertyName.FromProperty("[PROPERTY]");
     CustomDimension customDimension = new CustomDimension();
     // Make the request
     CustomDimension response = analyticsAdminServiceClient.CreateCustomDimension(parent, customDimension);
 }
Beispiel #6
0
        /// <summary>Snippet for GetCustomDimensionAsync</summary>
        /// <remarks>
        /// This snippet has been automatically generated for illustrative purposes only.
        /// It may require modifications to work in your environment.
        /// </remarks>
        public async Task GetCustomDimensionResourceNamesAsync()
        {
            // Create client
            AnalyticsAdminServiceClient analyticsAdminServiceClient = await AnalyticsAdminServiceClient.CreateAsync();

            // Initialize request argument(s)
            CustomDimensionName name = CustomDimensionName.FromProperty("[PROPERTY]");
            // Make the request
            CustomDimension response = await analyticsAdminServiceClient.GetCustomDimensionAsync(name);
        }
Beispiel #7
0
        /// <summary>Snippet for CreateCustomDimensionAsync</summary>
        /// <remarks>
        /// This snippet has been automatically generated for illustrative purposes only.
        /// It may require modifications to work in your environment.
        /// </remarks>
        public async Task CreateCustomDimensionAsync()
        {
            // Create client
            AnalyticsAdminServiceClient analyticsAdminServiceClient = await AnalyticsAdminServiceClient.CreateAsync();

            // Initialize request argument(s)
            string          parent          = "properties/[PROPERTY]";
            CustomDimension customDimension = new CustomDimension();
            // Make the request
            CustomDimension response = await analyticsAdminServiceClient.CreateCustomDimensionAsync(parent, customDimension);
        }
 /// <summary>Snippet for GetCustomDimension</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void GetCustomDimensionRequestObject()
 {
     // Create client
     AnalyticsAdminServiceClient analyticsAdminServiceClient = AnalyticsAdminServiceClient.Create();
     // Initialize request argument(s)
     GetCustomDimensionRequest request = new GetCustomDimensionRequest
     {
         CustomDimensionName = CustomDimensionName.FromProperty("[PROPERTY]"),
     };
     // Make the request
     CustomDimension response = analyticsAdminServiceClient.GetCustomDimension(request);
 }
Beispiel #9
0
 /// <summary>
 /// Updates an existing view (CustomDimension). This method supports patch semantics.
 /// Documentation:https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/customDimensions/patch
 ///
 /// </summary>
 /// <param name="service">Valid Authenticated Analytics Service </param>
 /// <param name="Body">relevant portions of a management.CustomDimension resource, according to the rules of patch semantics.</param>
 /// <param name="accountId">Account ID to which the web property belongs </param>
 /// <param name="webPropertyId">Web property Id</param>
 /// <param name="profilesId">profile ID</param>
 /// <returns>Custom Dimensions resource https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/customDimensions#resource </returns>
 public static CustomDimension CustomDimensionPatch(AnalyticsService service, CustomDimension body, string accountId, string webPropertyId, string profilesId)
 {
     try
     {
         return(service.Management.CustomDimensions.Patch(body, accountId, webPropertyId, profilesId).Execute());
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return(null);
     }
 }
Beispiel #10
0
 /// <summary>Snippet for UpdateCustomDimension</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void UpdateCustomDimensionRequestObject()
 {
     // Create client
     AnalyticsAdminServiceClient analyticsAdminServiceClient = AnalyticsAdminServiceClient.Create();
     // Initialize request argument(s)
     UpdateCustomDimensionRequest request = new UpdateCustomDimensionRequest
     {
         CustomDimension = new CustomDimension(),
         UpdateMask      = new FieldMask(),
     };
     // Make the request
     CustomDimension response = analyticsAdminServiceClient.UpdateCustomDimension(request);
 }
Beispiel #11
0
        /// <summary>Snippet for CreateCustomDimensionAsync</summary>
        /// <remarks>
        /// This snippet has been automatically generated for illustrative purposes only.
        /// It may require modifications to work in your environment.
        /// </remarks>
        public async Task CreateCustomDimensionRequestObjectAsync()
        {
            // Create client
            AnalyticsAdminServiceClient analyticsAdminServiceClient = await AnalyticsAdminServiceClient.CreateAsync();

            // Initialize request argument(s)
            CreateCustomDimensionRequest request = new CreateCustomDimensionRequest
            {
                ParentAsPropertyName = PropertyName.FromProperty("[PROPERTY]"),
                CustomDimension      = new CustomDimension(),
            };
            // Make the request
            CustomDimension response = await analyticsAdminServiceClient.CreateCustomDimensionAsync(request);
        }
        public void AddCustomDimension(int id, string value)
        {
            if (CustomDimension == null)
            {
                CustomDimension = new List <CustomDimenison>();
            }

            if (CustomDimension.FirstOrDefault(d => id.Equals(d.Number)) != null)
            {
                throw new ArgumentOutOfRangeException(nameof(id), "${id} already exists");
            }

            CustomDimension.Add(new CustomDimenison(id, value));
        }
        /// <summary>
        /// Create a new custom dimension.
        /// Documentation https://developers.google.com/analytics/v3/reference/customDimensions/insert
        /// 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 analytics service.</param>
        /// <param name="accountId">Account ID for the custom dimension to create.</param>
        /// <param name="webPropertyId">Web property ID for the custom dimension to create.</param>
        /// <param name="body">A valid analytics v3 body.</param>
        /// <returns>CustomDimensionResponse</returns>
        public static CustomDimension Insert(analyticsService service, string accountId, string webPropertyId, CustomDimension body)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (body == null)
                {
                    throw new ArgumentNullException("body");
                }
                if (accountId == null)
                {
                    throw new ArgumentNullException(accountId);
                }
                if (webPropertyId == null)
                {
                    throw new ArgumentNullException(webPropertyId);
                }

                // Make the request.
                return(service.CustomDimensions.Insert(body, accountId, webPropertyId).Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request CustomDimensions.Insert failed.", ex);
            }
        }
        /// <summary>
        /// Updates an existing view (CustomDimension). This method supports patch semantics.
        /// Documentation:https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/customDimensions/update
        /// 
        /// </summary>
        /// <param name="service">Valid Authenticated Analytics Service </param>
        /// <param name="Body">relevant portions of a management.CustomDimension resource, according to the rules of patch semantics.</param>
        /// <param name="accountId">Account ID to which the web property belongs </param>
        /// <param name="webPropertyId">Web property Id</param>
        /// <param name="profilesId">profile ID</param>
        /// <returns>Custom Dimensions resource https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/customDimensions#resource </returns>
        public static CustomDimension CustomDimensionUpdate(AnalyticsService service, CustomDimension body, string accountId, string webPropertyId, string profilesId)
        {
            try
            {
                return service.Management.CustomDimensions.Update(body, accountId, webPropertyId, profilesId).Execute();
            }
            catch (Exception ex)
            {

                Console.WriteLine(ex.Message);
                return null;
            }
        }