Skip to content

Implement additional ad event confirmations #1890

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions components/brave_ads/browser/ads_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -606,8 +606,8 @@ void AdsServiceImpl::SetCatalogIssuers(std::unique_ptr<ads::IssuersInfo> info) {
rewards_service_->SetCatalogIssuers(info->ToJson());
}

void AdsServiceImpl::AdSustained(std::unique_ptr<ads::NotificationInfo> info) {
rewards_service_->AdSustained(info->ToJson());
void AdsServiceImpl::ConfirmAd(std::unique_ptr<ads::NotificationInfo> info) {
rewards_service_->ConfirmAd(info->ToJson());
}

void AdsServiceImpl::NotificationTimedOut(uint32_t timer_id,
Expand Down
2 changes: 1 addition & 1 deletion components/brave_ads/browser/ads_service_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class AdsServiceImpl : public AdsService,
const std::string GenerateUUID() const override;
void ShowNotification(std::unique_ptr<ads::NotificationInfo> info) override;
void SetCatalogIssuers(std::unique_ptr<ads::IssuersInfo> info) override;
void AdSustained(std::unique_ptr<ads::NotificationInfo> info) override;
void ConfirmAd(std::unique_ptr<ads::NotificationInfo> info) override;
uint32_t SetTimer(const uint64_t time_offset) override;
void KillTimer(uint32_t timer_id) override;
void URLRequest(const std::string& url,
Expand Down
2 changes: 1 addition & 1 deletion components/brave_rewards/browser/rewards_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class RewardsService : public KeyedService {
// TODO(Terry Mancey): remove this hack when ads is moved to the same process
// as ledger
virtual void SetCatalogIssuers(const std::string& json) = 0;
virtual void AdSustained(const std::string& json) = 0;
virtual void ConfirmAd(const std::string& json) = 0;
virtual void GetRewardsInternalsInfo(
GetRewardsInternalsInfoCallback callback) = 0;

Expand Down
17 changes: 11 additions & 6 deletions components/brave_rewards/browser/rewards_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1477,12 +1477,12 @@ std::pair<uint64_t, uint64_t> RewardsServiceImpl::GetEarningsRange() {
return std::make_pair(from_timestamp, to_timestamp);
}

void RewardsServiceImpl::AdSustained(const std::string& json) {
void RewardsServiceImpl::ConfirmAd(const std::string& json) {
if (!Connected()) {
return;
}

bat_ledger_->AdSustained(json);
bat_ledger_->ConfirmAd(json);
}

void RewardsServiceImpl::SetConfirmationsIsReady(const bool is_ready) {
Expand Down Expand Up @@ -1525,12 +1525,17 @@ void RewardsServiceImpl::OnGetConfirmationsHistory(
callback.Run(0, 0.0);
}

int total_viewed = info->transactions.size();
double estimated_earnings = 0.0;
if (total_viewed > 0) {
for (const auto& transaction : info->transactions) {
estimated_earnings += transaction.estimated_redemption_value;
int total_viewed = 0;

for (const auto& transaction : info->transactions) {
// "view" is defined in confirmations::kConfirmationTypeView
if (transaction.confirmation_type != "view") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we move this string into variable, so that we have it only in one place?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 fixed

continue;
}

estimated_earnings += transaction.estimated_redemption_value;
total_viewed++;
}

callback.Run(total_viewed, estimated_earnings);
Expand Down
2 changes: 1 addition & 1 deletion components/brave_rewards/browser/rewards_service_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ class RewardsServiceImpl : public RewardsService,
void SetUserChangedContribution() const override;
void SetAutoContribute(bool enabled) const override;
void SetCatalogIssuers(const std::string& json) override;
void AdSustained(const std::string& json) override;
void ConfirmAd(const std::string& json) override;
void SetConfirmationsIsReady(const bool is_ready) override;
void GetConfirmationsHistory(
brave_rewards::ConfirmationsHistoryCallback callback) override;
Expand Down
4 changes: 2 additions & 2 deletions components/services/bat_ads/bat_ads_client_mojo_bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,12 @@ void BatAdsClientMojoBridge::SetCatalogIssuers(
bat_ads_client_->SetCatalogIssuers(info->ToJson());
}

void BatAdsClientMojoBridge::AdSustained(
void BatAdsClientMojoBridge::ConfirmAd(
std::unique_ptr<ads::NotificationInfo> info) {
if (!connected())
return;

bat_ads_client_->AdSustained(info->ToJson());
bat_ads_client_->ConfirmAd(info->ToJson());
}

uint32_t BatAdsClientMojoBridge::SetTimer(const uint64_t time_offset) {
Expand Down
2 changes: 1 addition & 1 deletion components/services/bat_ads/bat_ads_client_mojo_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class BatAdsClientMojoBridge : public ads::AdsClient {
const std::string GenerateUUID() const override;
void ShowNotification(std::unique_ptr<ads::NotificationInfo> info) override;
void SetCatalogIssuers(std::unique_ptr<ads::IssuersInfo> info) override;
void AdSustained(std::unique_ptr<ads::NotificationInfo> info) override;
void ConfirmAd(std::unique_ptr<ads::NotificationInfo> info) override;
uint32_t SetTimer(const uint64_t time_offset) override;
void KillTimer(uint32_t timer_id) override;
void URLRequest(const std::string& url,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,10 @@ void AdsClientMojoBridge::SetCatalogIssuers(
}
}

void AdsClientMojoBridge::AdSustained(const std::string& notification_info) {
void AdsClientMojoBridge::ConfirmAd(const std::string& notification_info) {
auto info = std::make_unique<ads::NotificationInfo>();
if (info->FromJson(notification_info) == ads::Result::SUCCESS)
ads_client_->AdSustained(std::move(info));
ads_client_->ConfirmAd(std::move(info));
}

// static
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class AdsClientMojoBridge : public mojom::BatAdsClient,
void LoadSampleBundle(LoadSampleBundleCallback callback) override;
void ShowNotification(const std::string& notification_info) override;
void SetCatalogIssuers(const std::string& issuers_info) override;
void AdSustained(const std::string& notification_info) override;
void ConfirmAd(const std::string& notification_info) override;
void SaveBundleState(const std::string& bundle_state,
SaveBundleStateCallback callback) override;
void GetAds(const std::string& region,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ interface BatAdsClient {
(int32 status_code, string content, map<string, string> headers);
ShowNotification(string notification_info);
SetCatalogIssuers(string issuers_info);
AdSustained(string notification_info);
ConfirmAd(string notification_info);
SaveBundleState(string bundle_state) => (int32 result);
GetAds(string region, string category) =>
(int32 result, string region, string category, array<string> ad_info);
Expand Down
4 changes: 2 additions & 2 deletions components/services/bat_ledger/bat_ledger_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,8 @@ void BatLedgerImpl::SetCatalogIssuers(const std::string& info) {
ledger_->SetCatalogIssuers(info);
}

void BatLedgerImpl::AdSustained(const std::string& info) {
ledger_->AdSustained(info);
void BatLedgerImpl::ConfirmAd(const std::string& info) {
ledger_->ConfirmAd(info);
}

// static
Expand Down
2 changes: 1 addition & 1 deletion components/services/bat_ledger/bat_ledger_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class BatLedgerImpl : public mojom::BatLedger,

private:
void SetCatalogIssuers(const std::string& info) override;
void AdSustained(const std::string& info) override;
void ConfirmAd(const std::string& info) override;

// workaround to pass base::OnceCallback into std::bind
template <typename Callback>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ interface BatLedger {
GetAddressesForPaymentId() => (map<string, string> addresses);

SetCatalogIssuers(string info);
AdSustained(string info);
ConfirmAd(string info);
GetConfirmationsHistory(uint64 from_timestamp_seconds,
uint64 to_timestamp_seconds) => (string transactions);
GetRewardsInternalsInfo() => (string info);
Expand Down
2 changes: 2 additions & 0 deletions vendor/bat-native-ads/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ source_set("ads") {
# add this only when ledger and confirmations are in the same process
# rebase_path("bat-native-ledger", dep_base),
# rebase_path("bat-native-ads", dep_base),
"//brave/test:*",
]

output_name = "bat_native_ads"
Expand All @@ -70,6 +71,7 @@ source_set("ads") {
"include/bat/ads/bundle_state.h",
"include/bat/ads/client_info_platform_type.h",
"include/bat/ads/client_info.h",
"include/bat/ads/confirmation_type.h",
"include/bat/ads/export.h",
"include/bat/ads/issuer_info.h",
"include/bat/ads/issuers_info.h",
Expand Down
4 changes: 2 additions & 2 deletions vendor/bat-native-ads/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,9 @@ void ShowNotification(std::unique_ptr<NotificationInfo> info)
void SetCatalogIssuers(std::unique_ptr<IssuersInfo> info)
```

`AdSustained` should be called to inform Confirmations that an ad was sustained
`ConfirmAd` should be called to inform Confirmations that an Ad was clicked, viewed, dismissed or landed
```
void AdSustained(std::unique_ptr<NotificationInfo> info)
void ConfirmAd(std::unique_ptr<NotificationInfo> info)
```

`SetTimer` should create a timer to trigger after the time offset specified in seconds. If the timer was created successfully a unique identifier should be returned, otherwise returns `0`
Expand Down
2 changes: 1 addition & 1 deletion vendor/bat-native-ads/include/bat/ads/ads_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class ADS_EXPORT AdsClient {
virtual void SetCatalogIssuers(std::unique_ptr<IssuersInfo> info) = 0;

// Should be called to inform Confirmations that an ad was sustained
virtual void AdSustained(std::unique_ptr<NotificationInfo> info) = 0;
virtual void ConfirmAd(std::unique_ptr<NotificationInfo> info) = 0;

// Should create a timer to trigger after the time offset specified in
// seconds. If the timer was created successfully a unique identifier should
Expand Down
30 changes: 30 additions & 0 deletions vendor/bat-native-ads/include/bat/ads/confirmation_type.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* Copyright (c) 2019 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef BAT_ADS_CONFIRMATION_TYPE_H_
#define BAT_ADS_CONFIRMATION_TYPE_H_

#include <string>

#include "bat/ads/export.h"

namespace ads {

static char kConfirmationTypeClick[] = "click";
static char kConfirmationTypeDismiss[] = "dismiss";
static char kConfirmationTypeView[] = "view";
static char kConfirmationTypeLanded[] = "landed";

enum class ADS_EXPORT ConfirmationType {
UNKNOWN,
CLICK,
DISMISS,
VIEW,
LANDED
};

} // namespace ads

#endif // BAT_ADS_CONFIRMATION_TYPE_H_
2 changes: 2 additions & 0 deletions vendor/bat-native-ads/include/bat/ads/notification_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <string>

#include "bat/ads/export.h"
#include "bat/ads/confirmation_type.h"
#include "bat/ads/result.h"

namespace ads {
Expand All @@ -29,6 +30,7 @@ struct ADS_EXPORT NotificationInfo {
std::string text;
std::string url;
std::string uuid;
ConfirmationType type;
};

} // namespace ads
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace ads {

enum ADS_EXPORT NotificationResultInfoResultType {
enum class ADS_EXPORT NotificationResultInfoResultType {
CLICKED,
DISMISSED,
TIMEOUT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class MockAdsClient : public AdsClient {
MOCK_METHOD1(SetCatalogIssuers, void(
std::unique_ptr<IssuersInfo> info));

MOCK_METHOD1(AdSustained, void(
MOCK_METHOD1(ConfirmAd, void(
std::unique_ptr<NotificationInfo> info));

MOCK_METHOD1(SetTimer, uint32_t(
Expand Down
Loading