Skip to content

Commit

Permalink
Fixes multiple landed confirmations for the same ad view
Browse files Browse the repository at this point in the history
  • Loading branch information
tmancey committed Apr 28, 2020
1 parent 1348b4a commit 41e42b8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
20 changes: 14 additions & 6 deletions vendor/bat-native-ads/src/bat/ads/internal/ads_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -647,13 +647,23 @@ void AdsImpl::OnPageLoaded(
if (SameSite(url, last_shown_ad_notification_.target_url)) {
BLOG(INFO) << "Visited URL matches the last shown ad notification";

if (!SameSite(url, last_sustained_ad_notification_url_)) {
last_sustained_ad_notification_url_ = url;
if (last_sustained_ad_notification_.creative_instance_id !=
last_shown_ad_notification_.creative_instance_id) {
last_sustained_ad_notification_ = AdNotificationInfo();
}

if (!SameSite(url, last_sustained_ad_notification_.target_url)) {
last_sustained_ad_notification_ = last_shown_ad_notification_;

StartSustainingAdNotificationInteraction();
} else {
BLOG(INFO) << "Already sustaining ad notification interaction for "
"visited URL";
if (sustain_ad_notification_interaction_timer_.IsRunning()) {
BLOG(INFO) << "Already sustaining ad notification interaction for "
"visited URL";
} else {
BLOG(INFO) << "Already sustained ad notification interaction for "
"visited URL";
}
}

return;
Expand Down Expand Up @@ -1463,8 +1473,6 @@ void AdsImpl::StartSustainingAdNotificationInteraction() {
}

void AdsImpl::SustainAdNotificationInteractionIfNeeded() {
last_sustained_ad_notification_url_ = "";

if (!IsStillViewingAdNotification()) {
BLOG(INFO) << "Failed to sustain ad notification interaction. The domain "
"for the focused tab does not match the last shown ad notification for "
Expand Down
2 changes: 1 addition & 1 deletion vendor/bat-native-ads/src/bat/ads/internal/ads_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ class AdsImpl : public Ads {
AdNotificationInfo last_shown_ad_notification_;
CreativeAdNotificationInfo last_shown_creative_ad_notification_;
Timer sustain_ad_notification_interaction_timer_;
std::string last_sustained_ad_notification_url_;
AdNotificationInfo last_sustained_ad_notification_;
void StartSustainingAdNotificationInteraction();
void SustainAdNotificationInteractionIfNeeded();
bool IsStillViewingAdNotification() const;
Expand Down

0 comments on commit 41e42b8

Please sign in to comment.