Skip to content
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

20 Add matomo in public share feature #1438

Merged
merged 3 commits into from
Oct 1, 2024
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
17 changes: 17 additions & 0 deletions app/src/main/java/com/infomaniak/drive/MatomoDrive.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ object MatomoDrive : MatomoCore {
override val Context.tracker: Tracker get() = (this as MainApplication).matomoTracker
override val siteId = 8

const val ACTION_DOWNLOAD_NAME = "download"
const val ACTION_OPEN_WITH_NAME = "openWith"
const val ACTION_OPEN_BOOKMARK_NAME = "openBookmark"
const val ACTION_PRINT_PDF_NAME = "printPdf"
const val ACTION_SAVE_TO_KDRIVE_NAME = "saveToKDrive"
const val ACTION_SEND_FILE_COPY_NAME = "sendFileCopy"

const val PUBLIC_SHARE_ACTION_CATEGORY = "publicShareAction"

fun Fragment.trackCategoriesEvent(name: String, action: TrackerAction = TrackerAction.CLICK, value: Float? = null) {
trackEvent("categories", name, action, value)
}
Expand All @@ -37,6 +46,14 @@ object MatomoDrive : MatomoCore {
trackEvent("fileAction", name, action, value)
}

fun Context.trackPublicShareActionEvent(name: String, action: TrackerAction = TrackerAction.CLICK, value: Float? = null) {
trackEvent(PUBLIC_SHARE_ACTION_CATEGORY, name, action, value)
}

fun Context.trackPdfActivityActionEvent(name: String, action: TrackerAction = TrackerAction.CLICK, value: Float? = null) {
trackEvent("pdfActivityAction", name, action, value)
}

fun Fragment.trackShareRightsEvent(name: String, action: TrackerAction = TrackerAction.CLICK, value: Float? = null) {
context?.trackShareRightsEvent(name, action, value)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ abstract class BasePreviewSliderFragment : Fragment(), FileInfoActionsView.OnIte

protected lateinit var previewSliderAdapter: PreviewSliderAdapter
protected lateinit var userDrive: UserDrive
protected abstract val isFileShare: Boolean
protected abstract val isPublicShare: Boolean
private var isOverlayShown = true

override val currentContext by lazy { requireContext() }
Expand Down Expand Up @@ -130,11 +130,11 @@ abstract class BasePreviewSliderFragment : Fragment(), FileInfoActionsView.OnIte
previewSliderViewModel.currentPreview = currentFile
with(header) {
toggleEditVisibility(isVisible = currentFile.isOnlyOfficePreview())
toggleOpenWithVisibility(isVisible = !isFileShare && !currentFile.isOnlyOfficePreview())
toggleOpenWithVisibility(isVisible = !isPublicShare && !currentFile.isOnlyOfficePreview())
}

setPrintButtonVisibility(isGone = !currentFile.isPDF())
(bottomSheetView as? FileInfoActionsView)?.openWith?.isGone = isFileShare
(bottomSheetView as? FileInfoActionsView)?.openWith?.isGone = isPublicShare
updateBottomSheetWithCurrentFile()
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ class FileInfoActionsBottomSheetDialog : BottomSheetDialogFragment(), FileInfoAc

override fun shareFile() = Unit
override fun saveToKDrive() = Unit
override fun printClicked() = Unit

companion object {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ import androidx.fragment.app.DialogFragment
import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.infomaniak.drive.MatomoDrive.ACTION_OPEN_BOOKMARK_NAME
import com.infomaniak.drive.MatomoDrive.ACTION_OPEN_WITH_NAME
import com.infomaniak.drive.MatomoDrive.ACTION_PRINT_PDF_NAME
import com.infomaniak.drive.MatomoDrive.ACTION_SAVE_TO_KDRIVE_NAME
import com.infomaniak.drive.MatomoDrive.ACTION_SEND_FILE_COPY_NAME
import com.infomaniak.drive.R
import com.infomaniak.drive.databinding.DialogDownloadProgressBinding
import com.infomaniak.drive.utils.showSnackbar
Expand Down Expand Up @@ -82,11 +87,11 @@ abstract class BaseDownloadProgressDialog : DialogFragment() {
}
}

enum class DownloadAction(val value: String) {
OPEN_BOOKMARK("open_bookmark"),
OPEN_WITH("open_with"),
PRINT_PDF("print_pdf"),
SAVE_TO_DRIVE("save_to_drive"),
SEND_COPY("send_copy"),
enum class DownloadAction(val value: String, val matomoValue: String) {
OPEN_BOOKMARK("open_bookmark", ACTION_OPEN_BOOKMARK_NAME),
OPEN_WITH("open_with", ACTION_OPEN_WITH_NAME),
PRINT_PDF("print_pdf", ACTION_PRINT_PDF_NAME),
SAVE_TO_DRIVE("save_to_drive", ACTION_SAVE_TO_KDRIVE_NAME),
SEND_COPY("send_copy", ACTION_SEND_FILE_COPY_NAME),
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,7 @@ abstract class MultiSelectActionsBottomSheetDialog(private val matomoCategory: S
}

binding.downloadFile.apply {
setOnClickListener {
if (drivePermissions.checkWriteStoragePermission()) {
trackEvent(matomoCategory, "bulkDownload")
download()
}
}

setOnClickListener { if (drivePermissions.checkWriteStoragePermission()) download() }
isVisible = navigationArgs.fileIds.isNotEmpty() || navigationArgs.isAllSelected
}
}
Expand All @@ -181,6 +175,7 @@ abstract class MultiSelectActionsBottomSheetDialog(private val matomoCategory: S
}

private fun download() {
trackEvent(matomoCategory, "bulkDownload")
if (navigationArgs.areAllFromTheSameFolder) downloadArchive() else downloadFiles()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.navigation.NavController
import androidx.navigation.fragment.NavHostFragment
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.infomaniak.drive.MatomoDrive.ACTION_PRINT_PDF_NAME
import com.infomaniak.drive.MatomoDrive.ACTION_SAVE_TO_KDRIVE_NAME
import com.infomaniak.drive.MatomoDrive.ACTION_SEND_FILE_COPY_NAME
import com.infomaniak.drive.MatomoDrive.trackPdfActivityActionEvent
import com.infomaniak.drive.R
import com.infomaniak.drive.data.models.ExtensionType
import com.infomaniak.drive.data.models.File
Expand Down Expand Up @@ -123,10 +127,12 @@ class PreviewPDFActivity : AppCompatActivity(), OnItemClickListener {
}

override fun shareFile() {
trackPdfActivityActionEvent(ACTION_SEND_FILE_COPY_NAME)
shareFile { previewPDFHandler.externalFileUri }
}

override fun saveToKDrive() {
trackPdfActivityActionEvent(ACTION_SAVE_TO_KDRIVE_NAME)
previewPDFHandler.externalFileUri?.let(::saveToKDrive)
}

Expand All @@ -135,7 +141,7 @@ class PreviewPDFActivity : AppCompatActivity(), OnItemClickListener {
}

override fun printClicked() {
super.printClicked()
trackPdfActivityActionEvent(ACTION_PRINT_PDF_NAME)
previewPDFHandler.printClicked(
context = this,
onError = { showSnackbar(R.string.errorFileNotFound) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.navArgs
import androidx.navigation.navGraphViewModels
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.infomaniak.drive.MatomoDrive.ACTION_PRINT_PDF_NAME
import com.infomaniak.drive.MatomoDrive.trackFileActionEvent
import com.infomaniak.drive.R
import com.infomaniak.drive.data.api.UploadTask.Companion.LIMIT_EXCEEDED_ERROR_CODE
import com.infomaniak.drive.data.cache.FileController
Expand Down Expand Up @@ -59,7 +61,7 @@ class PreviewSliderFragment : BasePreviewSliderFragment(), FileInfoActionsView.O
override val bottomSheetBehavior: BottomSheetBehavior<View>
get() = BottomSheetBehavior.from(binding.bottomSheetFileInfos)

override val isFileShare = false
override val isPublicShare = false
override val ownerFragment = this

override val selectFolderResultLauncher = registerForActivityResult(StartActivityForResult()) {
Expand Down Expand Up @@ -327,7 +329,7 @@ class PreviewSliderFragment : BasePreviewSliderFragment(), FileInfoActionsView.O
override fun onCacheAddedToOffline() = Unit

override fun printClicked() {
super<BasePreviewSliderFragment>.printClicked()
requireContext().trackFileActionEvent(ACTION_PRINT_PDF_NAME)
previewPDFHandler.printClicked(
context = requireContext(),
onDefaultCase = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import android.content.Intent
import androidx.annotation.StringRes
import androidx.core.content.FileProvider
import androidx.lifecycle.LifecycleOwner
import com.infomaniak.drive.MatomoDrive.ACTION_DOWNLOAD_NAME
import com.infomaniak.drive.MatomoDrive.trackPublicShareActionEvent
import androidx.lifecycle.lifecycleScope
import com.infomaniak.drive.R
import com.infomaniak.drive.data.models.File
Expand Down Expand Up @@ -62,12 +64,11 @@ interface OnPublicShareItemClickListener : FileInfoActionsView.OnItemClickListen
override fun saveToKDrive() = startAction(DownloadAction.SAVE_TO_DRIVE)

override fun downloadFileClicked() {
super.downloadFileClicked()
currentContext.trackPublicShareActionEvent(ACTION_DOWNLOAD_NAME)
currentFile?.let { currentContext.downloadFile(drivePermissions, it, ::onDownloadSuccess) }
}

override fun printClicked() {
super.printClicked()
previewPDFHandler?.printClicked(
context = currentContext,
onDefaultCase = { startAction(DownloadAction.PRINT_PDF) },
Expand All @@ -93,6 +94,7 @@ interface OnPublicShareItemClickListener : FileInfoActionsView.OnItemClickListen
}

private fun executeDownloadAction(downloadAction: DownloadAction, cacheFile: IOFile) = runCatching {
currentContext.trackPublicShareActionEvent(downloadAction.matomoValue)
val uri = FileProvider.getUriForFile(currentContext, currentContext.getString(R.string.FILE_AUTHORITY), cacheFile)

when (downloadAction) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.navArgs
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.google.android.material.button.MaterialButton
import com.infomaniak.drive.MatomoDrive.ACTION_OPEN_BOOKMARK_NAME
import com.infomaniak.drive.MatomoDrive.ACTION_SAVE_TO_KDRIVE_NAME
import com.infomaniak.drive.MatomoDrive.trackPublicShareActionEvent
import com.infomaniak.drive.R
import com.infomaniak.drive.data.models.File
import com.infomaniak.drive.ui.SaveExternalFilesActivity
Expand All @@ -53,6 +56,7 @@ import com.infomaniak.drive.utils.FilePresenter.openFolder
import com.infomaniak.drive.utils.IOFile
import com.infomaniak.drive.views.FileInfoActionsView.OnItemClickListener.Companion.downloadFile
import com.infomaniak.lib.core.utils.SnackbarUtils.showSnackbar
import com.infomaniak.lib.core.utils.capitalizeFirstChar
import com.infomaniak.lib.core.utils.safeNavigate
import com.infomaniak.lib.core.utils.whenResultIsOk
import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -244,7 +248,10 @@ class PublicShareListFragment : FileListFragment() {

private fun executeOpenBookmarkAction(cacheFile: IOFile?) = runCatching {
val uri = FileProvider.getUriForFile(requireContext(), getString(R.string.FILE_AUTHORITY), cacheFile!!)
requireContext().openBookmarkIntent(cacheFile.name, uri)
with(requireContext()) {
trackPublicShareActionEvent(ACTION_OPEN_BOOKMARK_NAME)
openBookmarkIntent(cacheFile.name, uri)
}
}.onFailure { exception ->
exception.printStackTrace()
showSnackbar(
Expand All @@ -255,6 +262,7 @@ class PublicShareListFragment : FileListFragment() {

private fun downloadAllFiles() {
// RootSharedFile can either be a folder or a single file
requireContext().trackPublicShareActionEvent("downloadAllFiles")
publicShareViewModel.rootSharedFile.value?.let { file -> requireContext().downloadFile(drivePermissions, file) }
}

Expand All @@ -277,9 +285,11 @@ class PublicShareListFragment : FileListFragment() {
private fun setMainButton(importButton: MaterialButton) {
importButton.setOnClickListener {
if (AccountUtils.currentDriveId == -1) {
requireContext().trackPublicShareActionEvent("createAccountAd")
// TODO : Show bottomsheet to get app if this functionality is implemented by the back
Intent(requireActivity(), LoginActivity::class.java).also(::startActivity)
} else {
requireContext().trackPublicShareActionEvent("bulk${ACTION_SAVE_TO_KDRIVE_NAME.capitalizeFirstChar()}")
Intent(requireActivity(), SaveExternalFilesActivity::class.java).apply {
action = Intent.ACTION_SEND
putExtras(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import android.view.View
import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.fragment.app.activityViewModels
import com.infomaniak.drive.MatomoDrive.PUBLIC_SHARE_ACTION_CATEGORY
import com.infomaniak.drive.data.api.ApiRoutes
import com.infomaniak.drive.ui.fileList.multiSelect.MultiSelectActionsBottomSheetDialog
import com.infomaniak.lib.core.utils.DownloadManagerUtils
Expand Down Expand Up @@ -67,6 +68,6 @@ class PublicShareMultiSelectActionsBottomSheetDialog : MultiSelectActionsBottomS
}

companion object {
const val MATOMO_CATEGORY = "publicShare"
const val MATOMO_CATEGORY = PUBLIC_SHARE_ACTION_CATEGORY
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import androidx.core.widget.addTextChangedListener
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import com.infomaniak.drive.BuildConfig
import com.infomaniak.drive.MatomoDrive.trackPublicShareActionEvent
import com.infomaniak.drive.R
import com.infomaniak.drive.data.models.ShareLink
import com.infomaniak.drive.databinding.FragmentPublicSharePasswordBinding
Expand All @@ -50,7 +51,12 @@ class PublicSharePasswordFragment : Fragment() {

// TODO: Remove this and call setupValidationButton instead
// Also change the layout (description, button's title, input visibility)
passwordValidateButton.setOnClickListener { requireActivity().openDeepLinkInBrowser(getPublicShareUrl()) }
passwordValidateButton.setOnClickListener {
with(requireActivity()) {
trackPublicShareActionEvent("openInBrowser")
openDeepLinkInBrowser(getPublicShareUrl())
}
}

publicSharePasswordEditText.addTextChangedListener { publicSharePasswordLayout.error = null }
observeSubmitPasswordResult()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class PublicSharePreviewSliderFragment : BasePreviewSliderFragment(), OnPublicSh
override val bottomSheetBehavior: BottomSheetBehavior<View>
get() = BottomSheetBehavior.from(bottomSheetView)

override val isFileShare = true
override val isPublicShare = true
override val ownerFragment = this

override fun initCurrentFile() {
Expand Down
3 changes: 0 additions & 3 deletions app/src/main/java/com/infomaniak/drive/utils/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ import com.google.android.material.textfield.TextInputEditText
import com.google.android.material.textfield.TextInputLayout
import com.infomaniak.drive.BuildConfig
import com.infomaniak.drive.BuildConfig.SUPPORT_URL
import com.infomaniak.drive.MatomoDrive.trackFileActionEvent
import com.infomaniak.drive.MatomoDrive.trackShareRightsEvent
import com.infomaniak.drive.R
import com.infomaniak.drive.data.api.ApiRoutes
Expand Down Expand Up @@ -434,8 +433,6 @@ fun Context.formatShortBinarySize(size: Long, valueOnly: Boolean = false): Strin
}

fun Context.shareFile(getUriToShare: () -> Uri?) {
trackFileActionEvent("sendFileCopy")

val shareIntent = Intent().apply {
action = Intent.ACTION_SEND
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/com/infomaniak/drive/utils/FilePresenter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ import androidx.navigation.fragment.findNavController
import com.dd.plist.NSDictionary
import com.dd.plist.NSString
import com.dd.plist.PropertyListParser
import com.infomaniak.drive.MatomoDrive.ACTION_OPEN_BOOKMARK_NAME
import com.infomaniak.drive.MatomoDrive.trackEvent
import com.infomaniak.drive.MatomoDrive.trackFileActionEvent
import com.infomaniak.drive.R
import com.infomaniak.drive.data.models.File
import com.infomaniak.drive.data.models.File.Companion.getCloudAndFileUris
Expand Down Expand Up @@ -91,6 +93,7 @@ object FilePresenter {
}

fun Fragment.openBookmark(file: File) {
requireContext().trackFileActionEvent(ACTION_OPEN_BOOKMARK_NAME)
if (file.canUseStoredFile(requireContext())) {
openBookmarkIntent(file)
} else {
Expand Down
10 changes: 8 additions & 2 deletions app/src/main/java/com/infomaniak/drive/utils/PreviewUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.gson.JsonParser
import com.infomaniak.drive.MatomoDrive.ACTION_OPEN_WITH_NAME
import com.infomaniak.drive.MatomoDrive.trackFileActionEvent
import com.infomaniak.drive.MatomoDrive.trackPdfActivityActionEvent
import com.infomaniak.drive.MatomoDrive.trackPublicShareActionEvent
import com.infomaniak.drive.R
import com.infomaniak.drive.data.api.ApiRoutes
import com.infomaniak.drive.data.models.File
Expand Down Expand Up @@ -79,7 +82,6 @@ fun Activity.setupBottomSheetFileBehavior(
}

fun Context.saveToKDrive(externalFileUri: Uri) {
trackFileActionEvent("saveToKDrive")

Intent(this, SaveExternalFilesActivity::class.java).apply {
action = Intent.ACTION_SEND
Expand All @@ -102,7 +104,11 @@ fun Context.openWith(
userDrive: UserDrive = UserDrive(),
onDownloadFile: (() -> Unit)? = null,
) {
trackFileActionEvent("openWith")
when {
currentFile?.isPublicShared() == true -> trackPublicShareActionEvent(ACTION_OPEN_WITH_NAME)
externalFileUri != null -> trackPdfActivityActionEvent(ACTION_OPEN_WITH_NAME)
else -> trackFileActionEvent(ACTION_OPEN_WITH_NAME)
}

ownerFragment?.apply {
// This is only for fragments. For activities, the snackbar is shown in the openWith method.
Expand Down
Loading
Loading