Esempio n. 1
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="conversionName">The conversion type name that you'd like to attribute this
        /// upload to.</param>
        /// <param name="externalUploadId">The external upload ID can be any number that you use to
        /// keep track of your uploads.</param>
        /// <param name="emailAddresses">The email addresses for creating user identifiers.</param>
        public void Run(AdWordsUser user, string conversionName, long externalUploadId,
                        string[] emailAddresses)
        {
            // Get the OfflineDataUploadService.
            OfflineDataUploadService offlineDataUploadService =
                (OfflineDataUploadService)user.GetService(
                    AdWordsService.v201710.OfflineDataUploadService);

            // Create the first offline data row for upload.
            // This transaction occurred 7 days ago with amount of 200 USD.
            DateTime transactionTime1 = new DateTime();

            transactionTime1.AddDays(-7);
            long   transactionAmount1       = 200000000;
            string transactionCurrencyCode1 = "USD";

            UserIdentifier[] userIdentifierList1 = new UserIdentifier[] {
                CreateUserIdentifier(OfflineDataUploadUserIdentifierType.HASHED_EMAIL,
                                     emailAddresses[0]),
                CreateUserIdentifier(OfflineDataUploadUserIdentifierType.STATE, "New York")
            };
            OfflineData offlineData1 = CreateOfflineDataRow(transactionTime1, transactionAmount1,
                                                            transactionCurrencyCode1, conversionName, userIdentifierList1);

            // Create the second offline data row for upload.
            // This transaction occurred 14 days ago with amount of 450 EUR.
            DateTime transactionTime2 = new DateTime();

            transactionTime2.AddDays(-14);
            long   transactionAmount2       = 450000000;
            string transactionCurrencyCode2 = "EUR";

            UserIdentifier[] userIdentifierList2 = new UserIdentifier[] {
                CreateUserIdentifier(OfflineDataUploadUserIdentifierType.HASHED_EMAIL,
                                     emailAddresses[1]),
                CreateUserIdentifier(OfflineDataUploadUserIdentifierType.STATE, "California")
            };
            OfflineData offlineData2 = CreateOfflineDataRow(transactionTime2, transactionAmount2,
                                                            transactionCurrencyCode2, conversionName, userIdentifierList2);

            // Create offline data upload object.
            OfflineDataUpload offlineDataUpload = new OfflineDataUpload();

            offlineDataUpload.externalUploadId = externalUploadId;
            offlineDataUpload.offlineDataList  = new OfflineData[] { offlineData1, offlineData2 };

            // Optional: You can set the type of this upload.
            // offlineDataUpload.uploadType = OfflineDataUploadType.STORE_SALES_UPLOAD_FIRST_PARTY;

            // Create an offline data upload operation.
            OfflineDataUploadOperation offlineDataUploadOperation = new OfflineDataUploadOperation();

            offlineDataUploadOperation.@operator = Operator.ADD;
            offlineDataUploadOperation.operand   = offlineDataUpload;

            try {
                // Upload offline data to the server.
                OfflineDataUploadReturnValue result = offlineDataUploadService.mutate(
                    new OfflineDataUploadOperation[] { offlineDataUploadOperation });
                offlineDataUpload = result.value[0];

                // Print the upload ID and status.
                Console.WriteLine("Uploaded offline data with external upload ID {0}, " +
                                  "and upload status {1}.", offlineDataUpload.externalUploadId,
                                  offlineDataUpload.uploadStatus);

                // Print any partial data errors from the response. The order of the partial
                // data errors list is the same as the uploaded offline data list in the
                // request.
                if (offlineDataUpload.partialDataErrors != null)
                {
                    for (int i = 0; i < offlineDataUpload.partialDataErrors.Length; i++)
                    {
                        ApiError partialDataError = offlineDataUpload.partialDataErrors[i];
                        Console.WriteLine("Found a partial error for offline data {0} with error string: {1}.",
                                          i + 1, partialDataError.errorString);
                    }
                }
            } catch (Exception e) {
                throw new System.ApplicationException("Failed upload offline data conversions.", e);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="conversionName">The conversion type name that you'd like to attribute this
        /// upload to.</param>
        /// <param name="externalUploadId">The external upload ID can be any number that you use to
        /// keep track of your uploads.</param>
        /// <param name="emailAddresses">The email addresses for creating user identifiers.</param>
        /// <param name="advertiserUploadTime">The advertiser upload time. For times, use the format
        /// yyyyMMdd HHmmss tz. For more details on formats, see:
        /// https://developers.google.com/adwords/api/docs/appendix/codes-formats#date-and-time-formats
        /// For time zones, see:
        /// https://developers.google.com/adwords/api/docs/appendix/codes-formats#timezone-ids</param>
        /// <param name="bridgeMapVersionId">The version ID of the bridge map.</param>
        /// <param name="uploadType">The type of data upload.</param>
        /// <param name="partnerId">The partner ID</param>
        public void Run(AdWordsUser user, string conversionName, long externalUploadId,
                        string[] emailAddresses, string advertiserUploadTime, string bridgeMapVersionId,
                        OfflineDataUploadType uploadType, int partnerId)
        {
            using (OfflineDataUploadService offlineDataUploadService =
                       (OfflineDataUploadService)user.GetService(
                           AdWordsService.v201802.OfflineDataUploadService)) {
                offlineDataUploadService.RequestHeader.partialFailure = true;

                // Create the first offline data row for upload.
                // This transaction occurred 7 days ago with amount of 200 USD.
                DateTime transactionTime1 = DateTime.Now;
                transactionTime1.AddDays(-7);
                long             transactionAmount1       = 200000000;
                string           transactionCurrencyCode1 = "USD";
                UserIdentifier[] userIdentifierList1      = new UserIdentifier[] {
                    CreateUserIdentifier(OfflineDataUploadUserIdentifierType.HASHED_EMAIL,
                                         emailAddresses[0]),
                    CreateUserIdentifier(OfflineDataUploadUserIdentifierType.STATE, "New York")
                };
                OfflineData offlineData1 = CreateOfflineDataRow(transactionTime1, transactionAmount1,
                                                                transactionCurrencyCode1, conversionName, userIdentifierList1);

                // Create the second offline data row for upload.
                // This transaction occurred 14 days ago with amount of 450 EUR.
                DateTime transactionTime2 = DateTime.Now;
                transactionTime2.AddDays(-14);
                long             transactionAmount2       = 450000000;
                string           transactionCurrencyCode2 = "EUR";
                UserIdentifier[] userIdentifierList2      = new UserIdentifier[] {
                    CreateUserIdentifier(OfflineDataUploadUserIdentifierType.HASHED_EMAIL,
                                         emailAddresses[1]),
                    CreateUserIdentifier(OfflineDataUploadUserIdentifierType.STATE, "California")
                };
                OfflineData offlineData2 = CreateOfflineDataRow(transactionTime2, transactionAmount2,
                                                                transactionCurrencyCode2, conversionName, userIdentifierList2);

                // Create offline data upload object.
                OfflineDataUpload offlineDataUpload = new OfflineDataUpload();
                offlineDataUpload.externalUploadId = externalUploadId;
                offlineDataUpload.offlineDataList  = new OfflineData[] { offlineData1, offlineData2 };

                // Set the type and metadata of this upload.
                offlineDataUpload.uploadType = uploadType;
                StoreSalesUploadCommonMetadata storeSalesMetaData = null;

                switch (uploadType)
                {
                case OfflineDataUploadType.STORE_SALES_UPLOAD_FIRST_PARTY:
                    storeSalesMetaData = new FirstPartyUploadMetadata()
                    {
                        loyaltyRate           = 1,
                        transactionUploadRate = 1
                    };
                    break;

                case OfflineDataUploadType.STORE_SALES_UPLOAD_THIRD_PARTY:
                    storeSalesMetaData = new ThirdPartyUploadMetadata()
                    {
                        loyaltyRate           = 1.0,
                        transactionUploadRate = 1.0,
                        advertiserUploadTime  = advertiserUploadTime,
                        validTransactionRate  = 1.0,
                        partnerMatchRate      = 1.0,
                        partnerUploadRate     = 1.0,
                        bridgeMapVersionId    = bridgeMapVersionId,
                        partnerId             = partnerId
                    };
                    break;
                }

                UploadMetadata uploadMetadata = new UploadMetadata();
                uploadMetadata.Item = storeSalesMetaData;
                offlineDataUpload.uploadMetadata = uploadMetadata;

                // Create an offline data upload operation.
                OfflineDataUploadOperation offlineDataUploadOperation = new OfflineDataUploadOperation();
                offlineDataUploadOperation.@operator = Operator.ADD;
                offlineDataUploadOperation.operand   = offlineDataUpload;

                // Keep the operations in an array, so it may be reused later for error processing.
                List <OfflineDataUploadOperation> operations = new List <OfflineDataUploadOperation>();
                operations.Add(offlineDataUploadOperation);

                try {
                    // Upload offline data to the server.
                    OfflineDataUploadReturnValue result = offlineDataUploadService.mutate(
                        operations.ToArray());
                    offlineDataUpload = result.value[0];

                    // Print the upload ID and status.
                    Console.WriteLine("Uploaded offline data with external upload ID {0}, " +
                                      "and upload status {1}.", offlineDataUpload.externalUploadId,
                                      offlineDataUpload.uploadStatus);

                    // Print any partial failure errors from the response.
                    if (result.partialFailureErrors != null)
                    {
                        foreach (ApiError apiError in result.partialFailureErrors)
                        {
                            // Get the index of the failed operation from the error's field path elements.
                            int operationIndex = apiError.GetOperationIndex();
                            if (operationIndex != -1)
                            {
                                OfflineDataUpload failedOfflineDataUpload = operations[operationIndex].operand;
                                // Get the index of the entry in the offline data list from the error's field path
                                // elements.
                                int offlineDataListIndex = apiError.GetFieldPathIndex("offlineDataList");
                                Console.WriteLine("Offline data list entry {0} in operation {1} with external " +
                                                  "upload ID {2} and type '{3}' has triggered a failure for the following " +
                                                  "reason: '{4}'.",
                                                  offlineDataListIndex,
                                                  operationIndex,
                                                  failedOfflineDataUpload.externalUploadId,
                                                  failedOfflineDataUpload.uploadType,
                                                  apiError.errorString);
                            }
                            else
                            {
                                Console.WriteLine("A failure has occurred for the following reason: {0}",
                                                  apiError.errorString);
                            }
                        }
                    }
                } catch (Exception e) {
                    throw new System.ApplicationException("Failed upload offline data conversions.", e);
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="conversionName">The conversion type name that you'd like to attribute this
        /// upload to.</param>
        /// <param name="externalUploadId">The external upload ID can be any number that you use to
        /// keep track of your uploads.</param>
        /// <param name="emailAddresses">The email addresses for creating user identifiers.</param>
        /// <param name="advertiserUploadTime">The advertiser upload time. For times, use the format
        /// yyyyMMdd HHmmss tz. For more details on formats, see:
        /// https://developers.google.com/adwords/api/docs/appendix/codes-formats#date-and-time-formats
        /// For time zones, see:
        /// https://developers.google.com/adwords/api/docs/appendix/codes-formats#timezone-ids</param>
        /// <param name="bridgeMapVersionId">The version ID of the bridge map.</param>
        /// <param name="uploadType">The type of data upload.</param>
        /// <param name="partnerId">The partner ID</param>
        public void Run(AdWordsUser user, string conversionName, long externalUploadId,
                        string[] emailAddresses, string advertiserUploadTime, string bridgeMapVersionId,
                        OfflineDataUploadType uploadType, int partnerId)
        {
            using (OfflineDataUploadService offlineDataUploadService =
                       (OfflineDataUploadService)user.GetService(
                           AdWordsService.v201710.OfflineDataUploadService)) {
                // Create the first offline data row for upload.
                // This transaction occurred 7 days ago with amount of 200 USD.
                DateTime transactionTime1 = new DateTime();
                transactionTime1.AddDays(-7);
                long             transactionAmount1       = 200000000;
                string           transactionCurrencyCode1 = "USD";
                UserIdentifier[] userIdentifierList1      = new UserIdentifier[] {
                    CreateUserIdentifier(OfflineDataUploadUserIdentifierType.HASHED_EMAIL,
                                         emailAddresses[0]),
                    CreateUserIdentifier(OfflineDataUploadUserIdentifierType.STATE, "New York")
                };
                OfflineData offlineData1 = CreateOfflineDataRow(transactionTime1, transactionAmount1,
                                                                transactionCurrencyCode1, conversionName, userIdentifierList1);

                // Create the second offline data row for upload.
                // This transaction occurred 14 days ago with amount of 450 EUR.
                DateTime transactionTime2 = new DateTime();
                transactionTime2.AddDays(-14);
                long             transactionAmount2       = 450000000;
                string           transactionCurrencyCode2 = "EUR";
                UserIdentifier[] userIdentifierList2      = new UserIdentifier[] {
                    CreateUserIdentifier(OfflineDataUploadUserIdentifierType.HASHED_EMAIL,
                                         emailAddresses[1]),
                    CreateUserIdentifier(OfflineDataUploadUserIdentifierType.STATE, "California")
                };
                OfflineData offlineData2 = CreateOfflineDataRow(transactionTime2, transactionAmount2,
                                                                transactionCurrencyCode2, conversionName, userIdentifierList2);

                // Create offline data upload object.
                OfflineDataUpload offlineDataUpload = new OfflineDataUpload();
                offlineDataUpload.externalUploadId = externalUploadId;
                offlineDataUpload.offlineDataList  = new OfflineData[] { offlineData1, offlineData2 };

                // Set the type and metadata of this upload.
                offlineDataUpload.uploadType = uploadType;
                StoreSalesUploadCommonMetadata storeSalesMetaData = null;

                switch (uploadType)
                {
                case OfflineDataUploadType.STORE_SALES_UPLOAD_FIRST_PARTY:
                    storeSalesMetaData = new FirstPartyUploadMetadata()
                    {
                        loyaltyRate           = 1,
                        transactionUploadRate = 1
                    };
                    break;

                case OfflineDataUploadType.STORE_SALES_UPLOAD_THIRD_PARTY:
                    storeSalesMetaData = new ThirdPartyUploadMetadata()
                    {
                        loyaltyRate           = 1.0,
                        transactionUploadRate = 1.0,
                        advertiserUploadTime  = advertiserUploadTime,
                        validTransactionRate  = 1.0,
                        partnerMatchRate      = 1.0,
                        partnerUploadRate     = 1.0,
                        bridgeMapVersionId    = bridgeMapVersionId,
                        partnerId             = partnerId
                    };
                    break;
                }

                UploadMetadata uploadMetadata = new UploadMetadata();
                uploadMetadata.Item = storeSalesMetaData;
                offlineDataUpload.uploadMetadata = uploadMetadata;

                // Create an offline data upload operation.
                OfflineDataUploadOperation offlineDataUploadOperation = new OfflineDataUploadOperation();
                offlineDataUploadOperation.@operator = Operator.ADD;
                offlineDataUploadOperation.operand   = offlineDataUpload;

                try {
                    // Upload offline data to the server.
                    OfflineDataUploadReturnValue result = offlineDataUploadService.mutate(
                        new OfflineDataUploadOperation[] { offlineDataUploadOperation });
                    offlineDataUpload = result.value[0];

                    // Print the upload ID and status.
                    Console.WriteLine("Uploaded offline data with external upload ID {0}, " +
                                      "and upload status {1}.", offlineDataUpload.externalUploadId,
                                      offlineDataUpload.uploadStatus);

                    // Print any partial data errors from the response. The order of the partial
                    // data errors list is the same as the uploaded offline data list in the
                    // request.
                    if (offlineDataUpload.partialDataErrors != null)
                    {
                        for (int i = 0; i < offlineDataUpload.partialDataErrors.Length; i++)
                        {
                            ApiError partialDataError = offlineDataUpload.partialDataErrors[i];
                            Console.WriteLine("Found a partial error for offline data {0} with error " +
                                              "string: {1}.", i + 1, partialDataError.errorString);
                        }
                    }
                } catch (Exception e) {
                    throw new System.ApplicationException("Failed upload offline data conversions.", e);
                }
            }
        }