/// <summary>Snippet for CreateOfflineUserDataJob</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void CreateOfflineUserDataJob()
 {
     // Create client
     OfflineUserDataJobServiceClient offlineUserDataJobServiceClient = OfflineUserDataJobServiceClient.Create();
     // Initialize request argument(s)
     string             customerId = "";
     OfflineUserDataJob job        = new OfflineUserDataJob();
     // Make the request
     CreateOfflineUserDataJobResponse response = offlineUserDataJobServiceClient.CreateOfflineUserDataJob(customerId, job);
 }
Exemplo n.º 2
0
 /// <summary>Snippet for CreateOfflineUserDataJob</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void CreateOfflineUserDataJobRequestObject()
 {
     // Create client
     OfflineUserDataJobServiceClient offlineUserDataJobServiceClient = OfflineUserDataJobServiceClient.Create();
     // Initialize request argument(s)
     CreateOfflineUserDataJobRequest request = new CreateOfflineUserDataJobRequest
     {
         CustomerId = "",
         Job        = new OfflineUserDataJob(),
     };
     // Make the request
     CreateOfflineUserDataJobResponse response = offlineUserDataJobServiceClient.CreateOfflineUserDataJob(request);
 }
Exemplo n.º 3
0
 /// <summary>Snippet for CreateOfflineUserDataJob</summary>
 public void CreateOfflineUserDataJobRequestObject()
 {
     // Snippet: CreateOfflineUserDataJob(CreateOfflineUserDataJobRequest, CallSettings)
     // Create client
     OfflineUserDataJobServiceClient offlineUserDataJobServiceClient = OfflineUserDataJobServiceClient.Create();
     // Initialize request argument(s)
     CreateOfflineUserDataJobRequest request = new CreateOfflineUserDataJobRequest
     {
         CustomerId   = "",
         Job          = new OfflineUserDataJob(),
         ValidateOnly = false,
     };
     // Make the request
     CreateOfflineUserDataJobResponse response = offlineUserDataJobServiceClient.CreateOfflineUserDataJob(request);
     // End snippet
 }
Exemplo n.º 4
0
        /// <summary>
        /// Creates and executes an asynchronous job to add users to the Customer Match user list.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The Google Ads customer ID for which calls are made.
        /// </param>
        /// <param name="userListResourceName">the resource name of the Customer Match user list
        /// to add users to</param>
        private static void AddUsersToCustomerMatchUserList(GoogleAdsClient client,
                                                            long customerId, string userListResourceName)
        {
            // Get the OfflineUserDataJobService.
            OfflineUserDataJobServiceClient service = client.GetService(
                Services.V4.OfflineUserDataJobService);

            // Creates a new offline user data job.
            OfflineUserDataJob offlineUserDataJob = new OfflineUserDataJob()
            {
                Type = OfflineUserDataJobType.CustomerMatchUserList,
                CustomerMatchUserListMetadata = new CustomerMatchUserListMetadata()
                {
                    UserList = userListResourceName
                }
            };

            // Issues a request to create the offline user data job.
            CreateOfflineUserDataJobResponse response1 = service.CreateOfflineUserDataJob(
                customerId.ToString(), offlineUserDataJob);
            string offlineUserDataJobResourceName = response1.ResourceName;

            Console.WriteLine($"Created an offline user data job with resource name: " +
                              $"'{offlineUserDataJobResourceName}'.");

            AddOfflineUserDataJobOperationsRequest request =
                new AddOfflineUserDataJobOperationsRequest()
            {
                ResourceName         = offlineUserDataJobResourceName,
                Operations           = { BuildOfflineUserDataJobOperations() },
                EnablePartialFailure = true,
            };
            // Issues a request to add the operations to the offline user data job.
            AddOfflineUserDataJobOperationsResponse response2 =
                service.AddOfflineUserDataJobOperations(request);

            // Prints the status message if any partial failure error is returned.
            // Note: The details of each partial failure error are not printed here,
            // you can refer to the example HandlePartialFailure.cs to learn more.
            if (response2.PartialFailureError == null)
            {
                // Extracts the partial failure from the response status.
                GoogleAdsFailure partialFailure = response2.PartialFailure;
                Console.WriteLine($"{partialFailure.Errors.Count} partial failure error(s) " +
                                  $"occurred");
            }
            Console.WriteLine("The operations are added to the offline user data job.");

            // Issues an asynchronous request to run the offline user data job for executing
            // all added operations.
            Operation <Empty, Empty> operationResponse =
                service.RunOfflineUserDataJob(offlineUserDataJobResourceName);

            Console.WriteLine("Asynchronous request to execute the added operations started.");;
            Console.WriteLine("Waiting until operation completes.");

            // PollUntilCompleted() implements a default back-off policy for retrying. You can
            // tweak the polling behaviour using a PollSettings as illustrated below.
            operationResponse.PollUntilCompleted(new PollSettings(
                                                     Expiration.FromTimeout(TimeSpan.FromSeconds(MAX_TOTAL_POLL_INTERVAL_SECONDS)),
                                                     TimeSpan.FromSeconds(POLL_FREQUENCY_SECONDS)));

            if (operationResponse.IsCompleted)
            {
                Console.WriteLine($"Offline user data job with resource name " +
                                  $"'{offlineUserDataJobResourceName}' has finished.");
            }
            else
            {
                Console.WriteLine($"Offline user data job with resource name" +
                                  $" '{offlineUserDataJobResourceName}' is pending after " +
                                  $"{MAX_TOTAL_POLL_INTERVAL_SECONDS} seconds.");
            }
        }
        /// <summary>
        /// Creates an offline user data job for uploading store sales transactions.
        /// </summary>
        /// <param name="offlineUserDataJobServiceClient">The offline user data job service
        ///     client.</param>
        /// <param name="customerId">The Google Ads customer ID for which the call is made.</param>
        /// <param name="offlineUserDataJobType">The type of user data in the job (first or third
        ///     party). If you have an official store sales partnership with Google, use
        ///     StoreSalesUploadThirdParty. Otherwise, use StoreSalesUploadFirstParty or
        ///     omit this parameter.</param>
        /// <param name="externalId">Optional (but recommended) external ID to identify the offline
        ///     user data job.</param>
        /// <param name="advertiserUploadDateTime">Date and time the advertiser uploaded data to the
        ///     partner. Only required if uploading third party data.</param>
        /// <param name="bridgeMapVersionId">Version of partner IDs to be used for uploads. Only
        ///     required if uploading third party data.</param>
        /// <param name="partnerId">ID of the third party partner. Only required if uploading third
        ///     party data.</param>
        /// <returns>The resource name of the created job.</returns>
        private string CreateOfflineUserDataJob(
            OfflineUserDataJobServiceClient offlineUserDataJobServiceClient, long customerId,
            OfflineUserDataJobType offlineUserDataJobType, long?externalId,
            string advertiserUploadDateTime, string bridgeMapVersionId, long?partnerId)
        {
            // TIP: If you are migrating from the AdWords API, please note that Google Ads API uses
            // the term "fraction" instead of "rate". For example, loyaltyRate in the AdWords API is
            // called loyaltyFraction in the Google Ads API.

            // Please refer to https://support.google.com/google-ads/answer/7506124 for additional
            // details.
            StoreSalesMetadata storeSalesMetadata = new StoreSalesMetadata()
            {
                // Sets the fraction of your overall sales that you (or the advertiser, in the third
                // party case) can associate with a customer (email, phone number, address, etc.) in
                // your database or loyalty program.
                // For example, set this to 0.7 if you have 100 transactions over 30 days, and out
                // of those 100 transactions, you can identify 70 by an email address or phone
                // number.
                LoyaltyFraction = 0.7,
                // Sets the fraction of sales you're uploading out of the overall sales that you (or
                // the advertiser, in the third party case) can associate with a customer. In most
                // cases, you will set this to 1.0.
                // Continuing the example above for loyalty fraction, a value of 1.0 here indicates
                // that you are uploading all 70 of the transactions that can be identified by an
                // email address or phone number.
                TransactionUploadFraction = 1.0
            };

            // Creates additional metadata required for uploading third party data.
            if (offlineUserDataJobType == OfflineUserDataJobType.StoreSalesUploadThirdParty)
            {
                StoreSalesThirdPartyMetadata storeSalesThirdPartyMetadata =
                    new StoreSalesThirdPartyMetadata()
                {
                    // The date/time must be in the format "yyyy-MM-dd hh:mm:ss".
                    AdvertiserUploadDateTime = advertiserUploadDateTime,

                    // Sets the fraction of transactions you received from the advertiser that
                    // have valid formatting and values. This captures any transactions the
                    // advertiser provided to you but which you are unable to upload to Google
                    // due to formatting errors or missing data.
                    // In most cases, you will set this to 1.0.
                    ValidTransactionFraction = 1.0,

                    // Sets the fraction of valid transactions (as defined above) you received
                    // from the advertiser that you (the third party) have matched to an
                    // external user ID on your side.
                    // In most cases, you will set this to 1.0.
                    PartnerMatchFraction = 1.0,

                    // Sets the fraction of transactions you (the third party) are uploading out
                    // of the transactions you received from the advertiser that meet both of
                    // the following criteria:
                    // 1. Are valid in terms of formatting and values. See valid transaction
                    // fraction above.
                    // 2. You matched to an external user ID on your side. See partner match
                    // fraction above.
                    // In most cases, you will set this to 1.0.
                    PartnerUploadFraction = 1.0,

                    // Sets the version of partner IDs to be used for uploads.
                    // Please speak with your Google representative to get the values to use for
                    // the bridge map version and partner IDs.
                    BridgeMapVersionId = bridgeMapVersionId,

                    // Sets the third party partner ID uploading the transactions.
                    PartnerId = partnerId
                };

                storeSalesMetadata.ThirdPartyMetadata = storeSalesThirdPartyMetadata;
            }

            // Creates a new offline user data job.
            OfflineUserDataJob offlineUserDataJob = new OfflineUserDataJob()
            {
                Type = offlineUserDataJobType,
                StoreSalesMetadata = storeSalesMetadata
            };

            if (externalId.HasValue)
            {
                offlineUserDataJob.ExternalId = externalId.Value;
            }

            // Issues a request to create the offline user data job.
            CreateOfflineUserDataJobResponse createOfflineUserDataJobResponse =
                offlineUserDataJobServiceClient.CreateOfflineUserDataJob(
                    customerId.ToString(), offlineUserDataJob);
            string offlineUserDataJobResourceName = createOfflineUserDataJobResponse.ResourceName;

            Console.WriteLine("Created an offline user data job with resource name: " +
                              $"{offlineUserDataJobResourceName}.");
            return(offlineUserDataJobResourceName);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Creates and executes an asynchronous job to add users to the Customer Match user list.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The Google Ads customer ID for which calls are made.
        /// </param>
        /// <param name="userListResourceName">the resource name of the Customer Match user list
        /// to add users to</param>
        /// <remarks>Resource of the offline user data job.</remarks>
        // [START add_customer_match_user_list]
        private static string AddUsersToCustomerMatchUserList(GoogleAdsClient client,
                                                              long customerId, string userListResourceName)
        {
            // Get the OfflineUserDataJobService.
            OfflineUserDataJobServiceClient service = client.GetService(
                Services.V10.OfflineUserDataJobService);

            // Creates a new offline user data job.
            OfflineUserDataJob offlineUserDataJob = new OfflineUserDataJob()
            {
                Type = OfflineUserDataJobType.CustomerMatchUserList,
                CustomerMatchUserListMetadata = new CustomerMatchUserListMetadata()
                {
                    UserList = userListResourceName
                }
            };

            // Issues a request to create the offline user data job.
            CreateOfflineUserDataJobResponse response1 = service.CreateOfflineUserDataJob(
                customerId.ToString(), offlineUserDataJob);
            string offlineUserDataJobResourceName = response1.ResourceName;

            Console.WriteLine($"Created an offline user data job with resource name: " +
                              $"'{offlineUserDataJobResourceName}'.");

            AddOfflineUserDataJobOperationsRequest request =
                new AddOfflineUserDataJobOperationsRequest()
            {
                ResourceName         = offlineUserDataJobResourceName,
                Operations           = { BuildOfflineUserDataJobOperations() },
                EnablePartialFailure = true,
            };
            // Issues a request to add the operations to the offline user data job.
            AddOfflineUserDataJobOperationsResponse response2 =
                service.AddOfflineUserDataJobOperations(request);

            // Prints the status message if any partial failure error is returned.
            // Note: The details of each partial failure error are not printed here,
            // you can refer to the example HandlePartialFailure.cs to learn more.
            if (response2.PartialFailureError != null)
            {
                // Extracts the partial failure from the response status.
                GoogleAdsFailure partialFailure = response2.PartialFailure;
                Console.WriteLine($"{partialFailure.Errors.Count} partial failure error(s) " +
                                  $"occurred");
            }
            Console.WriteLine("The operations are added to the offline user data job.");

            // Issues an asynchronous request to run the offline user data job for executing
            // all added operations.
            Operation <Empty, OfflineUserDataJobMetadata> operationResponse =
                service.RunOfflineUserDataJob(offlineUserDataJobResourceName);

            Console.WriteLine("Asynchronous request to execute the added operations started.");

            // Since offline user data jobs may take 24 hours or more to complete, it may not be
            // practical to do operationResponse.PollUntilCompleted() to wait for the results.
            // Instead, we save the offlineUserDataJobResourceName and use GoogleAdsService.Search
            // to check for the job status periodically.
            // In case you wish to follow the PollUntilCompleted or PollOnce approach, make sure
            // you keep both operationResponse and service variables alive until the polling
            // completes.

            return(offlineUserDataJobResourceName);
        }