Skip to content

Commit 885c47b

Browse files
committed
Integrate 42 day confirmation pixel
1 parent 484d747 commit 885c47b

File tree

3 files changed

+51
-3
lines changed

3 files changed

+51
-3
lines changed

pir/pir-impl/src/main/java/com/duckduckgo/pir/impl/pixels/OptOutConfirmationReporter.kt

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,10 @@ class RealOptOutConfirmationReporter @Inject constructor(
5252
if (activeBrokers.isEmpty() || allValidRequestedOptOutJobs.isEmpty()) return@withContext
5353

5454
allValidRequestedOptOutJobs.also {
55+
// Fire 7 day pixel
5556
it.attemptFirePixelForConfirmationDay(
5657
activeBrokers,
57-
7,
58+
INTERVAL_DAY_7,
5859
{ jobRecord -> jobRecord.confirmation7dayReportSentDateMs == 0L },
5960
{ brokerUrl -> pixelSender.reportBrokerOptOutConfirmed7Days(brokerUrl) },
6061
{ brokerUrl -> pixelSender.reportBrokerOptOutUnconfirmed7Days(brokerUrl) },
@@ -63,9 +64,10 @@ class RealOptOutConfirmationReporter @Inject constructor(
6364
},
6465
)
6566

67+
// Fire 14 day pixel
6668
it.attemptFirePixelForConfirmationDay(
6769
activeBrokers,
68-
14,
70+
INTERVAL_DAY_14,
6971
{ jobRecord -> jobRecord.confirmation14dayReportSentDateMs == 0L },
7072
{ brokerUrl -> pixelSender.reportBrokerOptOutConfirmed14Days(brokerUrl) },
7173
{ brokerUrl -> pixelSender.reportBrokerOptOutUnconfirmed14Days(brokerUrl) },
@@ -74,16 +76,29 @@ class RealOptOutConfirmationReporter @Inject constructor(
7476
},
7577
)
7678

79+
// Fire 21 day pixel
7780
it.attemptFirePixelForConfirmationDay(
7881
activeBrokers,
79-
21,
82+
INTERVAL_DAY_21,
8083
{ jobRecord -> jobRecord.confirmation21dayReportSentDateMs == 0L },
8184
{ brokerUrl -> pixelSender.reportBrokerOptOutConfirmed21Days(brokerUrl) },
8285
{ brokerUrl -> pixelSender.reportBrokerOptOutUnconfirmed21Days(brokerUrl) },
8386
{ jobRecord, now ->
8487
pirSchedulingRepository.markOptOutDay21ConfirmationPixelSent(jobRecord.extractedProfileId, now)
8588
},
8689
)
90+
91+
// Fire 42 day pixel
92+
it.attemptFirePixelForConfirmationDay(
93+
activeBrokers,
94+
INTERVAL_DAY_42,
95+
{ jobRecord -> jobRecord.confirmation42dayReportSentDateMs == 0L },
96+
{ brokerUrl -> pixelSender.reportBrokerOptOutConfirmed42Days(brokerUrl) },
97+
{ brokerUrl -> pixelSender.reportBrokerOptOutUnconfirmed42Days(brokerUrl) },
98+
{ jobRecord, now ->
99+
pirSchedulingRepository.markOptOutDay42ConfirmationPixelSent(jobRecord.extractedProfileId, now)
100+
},
101+
)
87102
}
88103
}
89104
}
@@ -120,4 +135,11 @@ class RealOptOutConfirmationReporter @Inject constructor(
120135
): Boolean {
121136
return now >= this.optOutRequestedDateInMillis + TimeUnit.DAYS.toMillis(interval)
122137
}
138+
139+
companion object {
140+
private const val INTERVAL_DAY_7 = 7L
141+
private const val INTERVAL_DAY_14 = 14L
142+
private const val INTERVAL_DAY_21 = 21L
143+
private const val INTERVAL_DAY_42 = 42L
144+
}
123145
}

pir/pir-impl/src/main/java/com/duckduckgo/pir/impl/store/PirSchedulingRepository.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ interface PirSchedulingRepository {
140140
extractedProfileId: Long,
141141
timestampMs: Long,
142142
)
143+
144+
suspend fun markOptOutDay42ConfirmationPixelSent(
145+
extractedProfileId: Long,
146+
timestampMs: Long,
147+
)
143148
}
144149

145150
@ContributesBinding(
@@ -362,6 +367,15 @@ class RealPirSchedulingRepository @Inject constructor(
362367
}
363368
}
364369

370+
override suspend fun markOptOutDay42ConfirmationPixelSent(
371+
extractedProfileId: Long,
372+
timestampMs: Long,
373+
) {
374+
withContext(dispatcherProvider.io()) {
375+
jobSchedulingDao()?.update42DayConfirmationReportSentDate(extractedProfileId, timestampMs)
376+
}
377+
}
378+
365379
private fun ScanJobRecordEntity.toRecord(): ScanJobRecord =
366380
ScanJobRecord(
367381
brokerName = this.brokerName,

pir/pir-impl/src/main/java/com/duckduckgo/pir/impl/store/db/JobSchedulingDao.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,4 +154,16 @@ interface JobSchedulingDao {
154154
extractedProfileId: Long,
155155
newDate: Long,
156156
)
157+
158+
@Query(
159+
"""
160+
UPDATE pir_optout_job_record
161+
SET reporting_fortyTwoDayConfirmationReportSentDateMs = :newDate
162+
WHERE extractedProfileId = :extractedProfileId
163+
""",
164+
)
165+
fun update42DayConfirmationReportSentDate(
166+
extractedProfileId: Long,
167+
newDate: Long,
168+
)
157169
}

0 commit comments

Comments
 (0)