Tải lên chuyển đổi

Hướng dẫn này cung cấp hướng dẫn chi tiết về cách tải lượt chuyển đổi ngoại tuyến lên bằng dịch vụ Conversionscủa Campaign Manager 360 API. Trước khi tiếp tục, bạn nên xem phần Tổng quan để biết thông tin giới thiệu về lượt chuyển đổi ngoại tuyến và làm quen với các khái niệm được thảo luận trong hướng dẫn này.

Định cấu hình tài nguyên lượt chuyển đổi

Bước đầu tiên trong quy trình tải lượt chuyển đổi lên là tạo một hoặc nhiều Conversion đối tượng tài nguyên. Mỗi đối tượng này đại diện cho một sự kiện chuyển đổi duy nhất và chứa một vài trường bắt buộc:

Trường Mô tả
floodlightActivityId Hoạt động Floodlight mà lượt chuyển đổi này sẽ được liên kết.
floodlightConfigurationId Cấu hình Floodlight mà hoạt động được chỉ định sử dụng.
ordinal Giá trị dùng để kiểm soát cách loại bỏ lượt chuyển đổi trùng lặp từ cùng một thiết bị hoặc người dùng trong cùng một ngày. Hãy xem phần Câu hỏi thường gặp để biết thêm thông tin.
timestampMicros Dấu thời gian của lượt chuyển đổi, tính bằng micrô giây kể từ thời gian bắt đầu của hệ thống Unix.

Ngoài ra, mỗi đối tượng phải chứa một trong các trường sau:

Trường Mô tả
encryptedUserId Một mã người dùng được mã hoá duy nhất lấy từ macro so khớp%m hoặc tính năng Chuyển dữ liệu.
encryptedUserIdCandidates[] Danh sách mã người dùng được mã hoá lấy từ macro so khớp%m hoặc tính năng Chuyển dữ liệu. Mã đầu tiên trong số các mã này có lượt hiển thị Floodlight được ghi lại trước timestampMicros được chỉ định sẽ được sử dụng. Nếu không có mã nào khớp với lượt hiển thị hiện có, thì hệ thống sẽ đưa ra lỗi.
dclid Mã lượt nhấp trên Mạng Hiển thị do Campaign Manager 360 hoặc Display & Video 360 tạo.
gclid Mã lượt nhấp của Google do Google Ads hoặc Search Ads 360 tạo.
matchId Giá trị nhận dạng riêng biệt do nhà quảng cáo tạo được truyền đến Campaign Manager 360 thông qua thẻ Floodlight.
mobileDeviceId Mã thiết bị di động chưa mã hoá ở định dạng Mã nhận dạng cho nhà quảng cáo (IDFA) hay Mã nhận dạng cho quảng cáo (AdID) hoặc Mã nhận dạng cho quảng cáo (IFA) trên TV kết nối Internet từ nền tảng thiết bị kết nối Internet cho TV được hỗ trợ (Roku, Fire TV, Android TV, Apple TV, Xbox, Samsung, Vizio).

Cuối cùng, mỗi lượt chuyển đổi có hai chỉ số:

Trường Mô tả
quantity Bắt buộc. Số lượng mặt hàng được liên kết với lượt chuyển đổi. Phải có ít nhất 1 lượt chuyển đổi để tính vào một số chỉ số (chẳng hạn như Tổng số lượt chuyển đổi).
value Số tiền (tính bằng đô la) được liên kết với lượt chuyển đổi. Được diễn giải theo đơn vị tiền tệ của nhà quảng cáo sở hữu cấu hình Floodlight.

Các trường không bắt buộc được ghi lại trong tài liệu tham khảo.

Ví dụ dưới đây minh hoạ cách tạo một đối tượng tài nguyên lượt chuyển đổi đơn giản:

C#

// Generate a timestamp in milliseconds since Unix epoch.
TimeSpan timeSpan = DateTime.UtcNow - new DateTime(1970, 1, 1);
long currentTimeInMilliseconds = (long) timeSpan.TotalMilliseconds;

// Find the Floodlight configuration ID based on the provided activity ID.
FloodlightActivity floodlightActivity =
    service.FloodlightActivities.Get(profileId, floodlightActivityId).Execute();
long floodlightConfigurationId = (long) floodlightActivity.FloodlightConfigurationId;

// Create the conversion.
Conversion conversion = new Conversion();
conversion.EncryptedUserId = conversionUserId;
conversion.FloodlightActivityId = floodlightActivityId;
conversion.FloodlightConfigurationId = floodlightConfigurationId;
conversion.Ordinal = currentTimeInMilliseconds.ToString();
conversion.TimestampMicros = currentTimeInMilliseconds * 1000;

Java

long currentTimeInMilliseconds = System.currentTimeMillis();

// Find Floodlight configuration ID based on the provided activity ID.
FloodlightActivity floodlightActivity = reporting.floodlightActivities()
    .get(profileId, floodlightActivityId).execute();
long floodlightConfigurationId = floodlightActivity.getFloodlightConfigurationId();

Conversion conversion = new Conversion();
conversion.setEncryptedUserId(encryptedUserId);
conversion.setFloodlightActivityId(floodlightActivityId);
conversion.setFloodlightConfigurationId(floodlightConfigurationId);
conversion.setOrdinal(String.valueOf(currentTimeInMilliseconds));
conversion.setTimestampMicros(currentTimeInMilliseconds * 1000);

PHP

$currentTimeInMicros = time() * 1000 * 1000;

// Find Floodlight configuration ID based on provided activity ID.
$activity = $this->service->floodlightActivities->get(
    $values['user_profile_id'],
    $values['floodlight_activity_id']
);
$floodlightConfigId = $activity->getFloodlightConfigurationId();

$conversion = new Google_Service_Dfareporting_Conversion();
$conversion->setEncryptedUserId($values['encrypted_user_id']);
$conversion->setFloodlightActivityId($values['floodlight_activity_id']);
$conversion->setFloodlightConfigurationId($floodlightConfigId);
$conversion->setOrdinal($currentTimeInMicros);
$conversion->setTimestampMicros($currentTimeInMicros);

Python

# Look up the Floodlight configuration ID based on activity ID.
floodlight_activity = (
    service.floodlightActivities()
    .get(profileId=str(profile_id), id=str(floodlight_activity_id))
    .execute()
)
floodlight_config_id = floodlight_activity['floodlightConfigurationId']

current_time_in_micros = int(time.time() * 1000000)

# Construct the conversion.
conversion = {
    'encryptedUserId': encrypted_user_id,
    'floodlightActivityId': floodlight_activity_id,
    'floodlightConfigurationId': floodlight_config_id,
    'ordinal': current_time_in_micros,
    'timestampMicros': current_time_in_micros
}

Ruby

# Look up the Floodlight configuration ID based on activity ID.
floodlight_activity = service.get_floodlight_activity(profile_id,
  floodlight_activity_id)
floodlight_config_id = floodlight_activity.floodlight_configuration_id

current_time_in_micros = DateTime.now.strftime('%Q').to_i * 1000

# Construct the conversion.
conversion = DfareportingUtils::API_NAMESPACE::Conversion.new(
  encrypted_user_id: encrypted_user_id,
  floodlight_activity_id: floodlight_activity_id,
  floodlight_configuration_id: floodlight_config_id,
  ordinal: current_time_in_micros,
  timestamp_micros: current_time_in_micros
)

Chỉ định thông tin mã hoá

Nếu bạn dự định phân bổ lượt chuyển đổi ngoại tuyến cho mã người dùng được mã hoá (như trong ví dụ trước), thì bạn cần cung cấp một số thông tin chi tiết về cách mã hoá các mã đó trong yêu cầu chèn. Cụ thể, bạn cần biết:

  1. Nguồn mã hoá, mô tả nơi một lô mã nhận dạng được mã hoá đến. Các giá trị có thể chấp nhận là AD_SERVING cho các mã nhận dạng có nguồn từ macro so khớp %m hoặc DATA_TRANSFER cho các mã nhận dạng có nguồn từ tệp Chuyển dữ liệu.

  2. Thực thể mã hoá là một tập hợp giá trị duy nhất dùng để mã hoá mã người dùng. Các giá trị này thường liên quan đến một tài khoản Campaign Manager 360 khi nguồn là tính năng Chuyển dữ liệu hoặc một nhà quảng cáo Campaign Manager 360 khi nguồn là macro %m, nhưng không phải lúc nào cũng như vậy. Nếu bạn không chắc chắn, hãy liên hệ với người đại diện tài khoản Campaign Manager 360 hoặc bộ phận hỗ trợ Campaign Manager 360 để biết thêm thông tin.

Khi cần thiết, việc tạo đối tượng EncryptionInfo chỉ định các giá trị này là bước thứ hai trong quy trình tải lượt chuyển đổi lên:

C#

// Create the encryption info.
EncryptionInfo encryptionInfo = new EncryptionInfo();
encryptionInfo.EncryptionEntityId = encryptionEntityId;
encryptionInfo.EncryptionEntityType = encryptionEntityType;
encryptionInfo.EncryptionSource = encryptionSource;

Java

// Create the encryption info.
EncryptionInfo encryptionInfo = new EncryptionInfo();
encryptionInfo.setEncryptionEntityId(encryptionEntityId);
encryptionInfo.setEncryptionEntityType(encryptionEntityType);
encryptionInfo.setEncryptionSource(encryptionSource);

PHP

$encryptionInfo = new Google_Service_Dfareporting_EncryptionInfo();
$encryptionInfo->setEncryptionEntityId($values['encryption_entity_id']);
$encryptionInfo->setEncryptionEntityType($values['encryption_entity_type']);
$encryptionInfo->setEncryptionSource($values['encryption_source']);

Python

# Construct the encryption info.
encryption_info = {
    'encryptionEntityId': encryption_entity_id,
    'encryptionEntityType': encryption_entity_type,
    'encryptionSource': encryption_source
}

Ruby

# Construct the encryption info.
encryption_info = DfareportingUtils::API_NAMESPACE::EncryptionInfo.new(
  encryption_entity_id: encryption[:entity_id],
  encryption_entity_type: encryption[:entity_type],
  encryption_source: encryption[:source]
)

Xin lưu ý rằng mỗi yêu cầu chèn chỉ có thể chứa một đối tượng EncryptionInfo. Điều này có nghĩa là tất cả lượt chuyển đổi có trong một yêu cầu nhất định phải có nguồn gốc từ cùng một nguồn và sử dụng cùng một thực thể mã hoá.

Tạo yêu cầu chèn

Bước cuối cùng trong quy trình này là tải lượt chuyển đổi lên bằng lệnh gọi đến batchinsert. Phương thức này chấp nhận một đối tượng ConversionsBatchInsertRequest, kết hợp tập hợp lượt chuyển đổi cần tải lên với thông tin mã hoá được liên kết (khi cần):

C#

// Insert the conversion.
ConversionsBatchInsertRequest request = new ConversionsBatchInsertRequest();
request.Conversions = new List<Conversion>() { conversion };
request.EncryptionInfo = encryptionInfo;

ConversionsBatchInsertResponse response =
    service.Conversions.Batchinsert(request, profileId).Execute();

Java

ConversionsBatchInsertRequest request = new ConversionsBatchInsertRequest();
request.setConversions(ImmutableList.of(conversion));
request.setEncryptionInfo(encryptionInfo);

ConversionsBatchInsertResponse response = reporting.conversions()
    .batchinsert(profileId, request).execute();

PHP

$batch = new Google_Service_Dfareporting_ConversionsBatchInsertRequest();
$batch->setConversions([$conversion]);
$batch->setEncryptionInfo($encryptionInfo);

$result = $this->service->conversions->batchinsert(
    $values['user_profile_id'],
    $batch
);

Python

# Insert the conversion.
request_body = {
    'conversions': [conversion],
    'encryptionInfo': encryption_info
}
request = service.conversions().batchinsert(
    profileId=str(profile_id), body=request_body
)
response = request.execute()

Ruby

# Construct the batch insert request.
batch_insert_request =
  DfareportingUtils::API_NAMESPACE::ConversionsBatchInsertRequest.new(
    conversions: [conversion],
    encryption_info: encryption_info
  )

# Insert the conversion.
result = service.batchinsert_conversion(profile_id, batch_insert_request)

Xin lưu ý rằng Campaign Manager 360 cố gắng chèn từng lượt chuyển đổi trong yêu cầu của bạn trên cơ sở nỗ lực hết mình, thay vì chèn toàn bộ lô dưới dạng giao dịch tất cả hoặc không có gì. Nếu một số lượt chuyển đổi trong một lô không chèn được, thì những lượt chuyển đổi khác vẫn có thể chèn thành công. Do đó, bạn nên kiểm tra được trả về ConversionsBatchInsertResponse để xác định trạng thái của từng lượt chuyển đổi:

C#

// Handle the batchinsert response.
if (!response.HasFailures.Value) {
  Console.WriteLine("Successfully inserted conversion for encrypted user ID {0}.",
      conversionUserId);
} else {
  Console.WriteLine("Error(s) inserting conversion for encrypted user ID {0}:",
      conversionUserId);

  ConversionStatus status = response.Status[0];
  foreach(ConversionError error in status.Errors) {
    Console.WriteLine("\t[{0}]: {1}", error.Code, error.Message);
  }
}

Java

if (!response.getHasFailures()) {
  System.out.printf("Successfully inserted conversion for encrypted user ID %s.%n",
      encryptedUserId);
} else {
  System.out.printf("Error(s) inserting conversion for encrypted user ID %s:%n",
      encryptedUserId);

  // Retrieve the conversion status and report any errors found. If multiple conversions
  // were included in the original request, the response would contain a status for each.
  ConversionStatus status = response.getStatus().get(0);
  for (ConversionError error : status.getErrors()) {
    System.out.printf("\t[%s]: %s.%n", error.getCode(), error.getMessage());
  }
}

PHP

if (!$result->getHasFailures()) {
    printf(
        'Successfully inserted conversion for encrypted user ID %s.',
        $values['encrypted_user_id']
    );
} else {
    printf(
        'Error(s) inserting conversion for encrypted user ID %s:<br><br>',
        $values['encrypted_user_id']
    );

    $status = $result->getStatus()[0];
    foreach ($status->getErrors() as $error) {
        printf('[%s] %s<br>', $error->getCode(), $error->getMessage());
    }
}

Python

if not response['hasFailures']:
  print(
      'Successfully inserted conversion for encrypted user ID %s.'
      % encrypted_user_id
  )
else:
  print(
      'Error(s) inserting conversion for encrypted user ID %s.'
      % encrypted_user_id
  )

  status = response['status'][0]
  for error in status['errors']:
    print('\t[%s]: %s' % (error['code'], error['message']))

Ruby

if result.has_failures
  puts format('Error(s) inserting conversion for encrypted user ID %s.',
    encrypted_user_id)

  status = result.status[0]
  status.errors.each do |error|
    puts format("\t[%s]: %s", error.code, error.message)
  end
else
  puts format('Successfully inserted conversion for encrypted user ID %s.',
    encrypted_user_id)
end

Trường status của phản hồi, như bạn thấy ở trên, sẽ chứa một ConversionStatus đối tượng cho mọi lượt chuyển đổi có trong yêu cầu ban đầu. Nếu bạn chỉ quan tâm đến những lượt chuyển đổi không chèn được, thì bạn có thể sử dụng trường hasFailures để nhanh chóng xác định xem có lượt chuyển đổi nào trong lô được cung cấp không chèn được hay không.

Xác minh rằng lượt chuyển đổi đã được xử lý

Các lượt chuyển đổi được tải lên thường sẽ được xử lý và có sẵn để báo cáo trong vòng 24 giờ. Để xác minh xem các lượt chuyển đổi mà bạn đã tải lên có được xử lý hay không, bạn nên chạy báo cáo Lượt hiển thị Floodlight. Không giống như các báo cáo phân bổ khác, theo mặc định, các báo cáo này sẽ trả về cả lượt chuyển đổi được phân bổ (liên kết với một quảng cáo) và lượt chuyển đổi không được phân bổ. Điều này giúp bạn nhanh chóng kiểm tra xem các lượt chuyển đổi mà bạn đã gửi có được chuyển đến Campaign Manager 360 hay không.