Skip to content

Commit

Permalink
Sync: Pixels and Monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
malmstein committed Dec 19, 2023
1 parent 333a2c5 commit fb28dd5
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/src/internal/res/xml/network_security_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
<certificates src="user" />
</trust-anchors>
</base-config>
</network-security-config>
</network-security-config>
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.duckduckgo.sync.api.engine.SyncEngine.SyncTrigger.ACCOUNT_CREATION
import com.duckduckgo.sync.api.engine.SyncEngine.SyncTrigger.ACCOUNT_LOGIN
import com.duckduckgo.sync.crypto.*
import com.duckduckgo.sync.impl.Result.Error
import com.duckduckgo.sync.impl.Result.Success
import com.duckduckgo.sync.impl.pixels.*
import com.duckduckgo.sync.store.*
import com.duckduckgo.sync.store.SyncStore
Expand Down Expand Up @@ -104,6 +105,7 @@ class AppSyncAccountRepository @Inject constructor(
}

is Result.Success -> {
syncPixels.fireSignupDirectPixel()
syncStore.storeCredentials(account.userId, deviceId, deviceName, account.primaryKey, account.secretKey, result.data.token)
syncEngine.triggerSync(ACCOUNT_CREATION)
Timber.d("Sync-Account: recovery code is ${getRecoveryCode()}")
Expand Down Expand Up @@ -195,9 +197,11 @@ class AppSyncAccountRepository @Inject constructor(
val seal = nativeLib.seal(recoverKey, connectKeys.secretKey)

val result = syncApi.connect(token = token, deviceId = connectKeys.deviceId, publicKey = seal)
if (result is Error) {
syncPixels.fireSyncAccountErrorPixel(result)
when (result) {
is Error -> syncPixels.fireSyncAccountErrorPixel(result)
is Success -> syncPixels.fireSignupConnectPixel()
}

return result
}

Expand Down Expand Up @@ -352,6 +356,7 @@ class AppSyncAccountRepository @Inject constructor(
}
}
syncStore.storeCredentials(userId, deviceId, deviceName, preLogin.primaryKey, decryptResult.decryptedData, result.data.token)
syncPixels.fireLoginPixel()
appCoroutineScope.launch(dispatcherProvider.io()) {
syncEngine.triggerSync(ACCOUNT_LOGIN)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class SyncDailyReportingWorker(
override suspend fun doWork(): Result {
return withContext(dispatchers.io()) {
if (syncAccountRepository.isSignedIn()) {
syncPixels.fireDailyPixel()
syncPixels.fireStatsPixel()
}
return@withContext Result.success()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,27 @@ import com.squareup.anvil.annotations.ContributesBinding
import javax.inject.Inject

interface SyncPixels {

/**
* Fired once per day, for all users with sync enabled
*/
fun fireDailyPixel()

/**
* Fired when adding new device to existing account
*/
fun fireLoginPixel()

/**
* Fired when user sets up a sync account from connect flow
*/
fun fireSignupConnectPixel()

/**
* Fired when user sets up a sync account directly.
*/
fun fireSignupDirectPixel()

fun fireStatsPixel()

fun fireOrphanPresentPixel(feature: String)
Expand Down Expand Up @@ -52,6 +73,22 @@ class RealSyncPixels @Inject constructor(
private val pixel: Pixel,
private val statsRepository: SyncStatsRepository,
) : SyncPixels {
override fun fireDailyPixel() {
pixel.fire(SyncPixelName.SYNC_DAILY_PIXEL)
}

override fun fireLoginPixel() {
pixel.fire(SyncPixelName.SYNC_LOGIN)
}

override fun fireSignupConnectPixel() {
pixel.fire(SyncPixelName.SYNC_SIGNUP_CONNECT)
}

override fun fireSignupDirectPixel() {
pixel.fire(SyncPixelName.SYNC_SIGNUP_DIRECT)
}

override fun fireStatsPixel() {
val dailyStats = statsRepository.getDailyStats()
pixel.fire(
Expand Down Expand Up @@ -130,7 +167,13 @@ class RealSyncPixels @Inject constructor(
}
}

//https://app.asana.com/0/72649045549333/1205649300615861
enum class SyncPixelName(override val pixelName: String) : Pixel.PixelName {
SYNC_DAILY_PIXEL("m_sync_daily"),
SYNC_LOGIN("m_sync_login"),
SYNC_SIGNUP_DIRECT("m_sync_signup_direct"),
SYNC_SIGNUP_CONNECT("m_sync_signup_connect"),

SYNC_SUCCESS_RATE("m_sync_daily_success_rate"),
SYNC_DAILY_ATTEMPTS("m_sync_daily_attempts"),
SYNC_ORPHAN_PRESENT("m_sync_orphan_present"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class AppSyncAccountRepositoryTest {
secretKey = secretKey,
token = token,
)
verify(syncPixels).fireSignupDirectPixel()
}

@Test
Expand Down Expand Up @@ -214,6 +215,8 @@ class AppSyncAccountRepositoryTest {
secretKey = secretKey,
token = token,
)

verify(syncPixels).fireLoginPixel()
}

@Test
Expand Down Expand Up @@ -354,6 +357,7 @@ class AppSyncAccountRepositoryTest {

verify(syncApi).connect(token, deviceId, encryptedRecoveryCode)
assertTrue(result is Success)
verify(syncPixels).fireSignupConnectPixel()
}

@Test
Expand All @@ -372,6 +376,7 @@ class AppSyncAccountRepositoryTest {

verify(syncApi).connect(token, deviceId, encryptedRecoveryCode)
assertTrue(result is Success)
verify(syncPixels).fireSignupConnectPixel()
}

@Test
Expand All @@ -386,6 +391,7 @@ class AppSyncAccountRepositoryTest {
val result = syncRepo.pollConnectionKeys()

assertTrue(result is Success)
verify(syncPixels).fireLoginPixel()
}

@Test
Expand Down

0 comments on commit fb28dd5

Please sign in to comment.