diff --git a/commands/daemon/daemon.go b/commands/daemon/daemon.go
index d68a5562fd0..a0369f97ad4 100644
--- a/commands/daemon/daemon.go
+++ b/commands/daemon/daemon.go
@@ -343,7 +343,6 @@ func (s *ArduinoCoreServerImpl) LibraryDownload(req *rpc.LibraryDownloadRequest,
 	resp, err := lib.LibraryDownload(
 		stream.Context(), req,
 		func(p *rpc.DownloadProgress) { stream.Send(&rpc.LibraryDownloadResponse{Progress: p}) },
-		"",
 	)
 	if err != nil {
 		return convertErrorToRPCStatus(err)
@@ -357,7 +356,6 @@ func (s *ArduinoCoreServerImpl) LibraryInstall(req *rpc.LibraryInstallRequest, s
 		stream.Context(), req,
 		func(p *rpc.DownloadProgress) { stream.Send(&rpc.LibraryInstallResponse{Progress: p}) },
 		func(p *rpc.TaskProgress) { stream.Send(&rpc.LibraryInstallResponse{TaskProgress: p}) },
-		"",
 	)
 	if err != nil {
 		return convertErrorToRPCStatus(err)
diff --git a/commands/lib/download.go b/commands/lib/download.go
index f9a1669e677..9d6c43cb875 100644
--- a/commands/lib/download.go
+++ b/commands/lib/download.go
@@ -32,8 +32,7 @@ var tr = i18n.Tr
 
 // LibraryDownload executes the download of the library.
 // A DownloadProgressCB callback function must be passed to monitor download progress.
-// queryParameter is passed for analysis purposes.
-func LibraryDownload(ctx context.Context, req *rpc.LibraryDownloadRequest, downloadCB rpc.DownloadProgressCB, queryParameter string) (*rpc.LibraryDownloadResponse, error) {
+func LibraryDownload(ctx context.Context, req *rpc.LibraryDownloadRequest, downloadCB rpc.DownloadProgressCB) (*rpc.LibraryDownloadResponse, error) {
 	logrus.Info("Executing `arduino-cli lib download`")
 
 	lm := commands.GetLibraryManager(req)
@@ -48,7 +47,7 @@ func LibraryDownload(ctx context.Context, req *rpc.LibraryDownloadRequest, downl
 		return nil, err
 	}
 
-	if err := downloadLibrary(lm, lib, downloadCB, func(*rpc.TaskProgress) {}, queryParameter); err != nil {
+	if err := downloadLibrary(lm, lib, downloadCB, func(*rpc.TaskProgress) {}, "download"); err != nil {
 		return nil, err
 	}
 
diff --git a/commands/lib/install.go b/commands/lib/install.go
index f5e995d4535..5ace0cddfd0 100644
--- a/commands/lib/install.go
+++ b/commands/lib/install.go
@@ -31,8 +31,7 @@ import (
 )
 
 // LibraryInstall resolves the library dependencies, then downloads and installs the libraries into the install location.
-// queryParameter is passed for analysis purposes and forwarded to the called functions. It is set to "depends" when a dependency is installed
-func LibraryInstall(ctx context.Context, req *rpc.LibraryInstallRequest, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB, queryParameter string) error {
+func LibraryInstall(ctx context.Context, req *rpc.LibraryInstallRequest, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) error {
 	lm := commands.GetLibraryManager(req)
 	if lm == nil {
 		return &arduino.InvalidInstanceError{}
@@ -98,21 +97,19 @@ func LibraryInstall(ctx context.Context, req *rpc.LibraryInstallRequest, downloa
 
 	for libRelease, installTask := range libReleasesToInstall {
 		// Checks if libRelease is the requested library and not a dependency
+		downloadReason := "depends"
 		if libRelease.GetName() == req.Name {
-			if err := downloadLibrary(lm, libRelease, downloadCB, taskCB, queryParameter); err != nil {
-				return err
-			}
-			if err := installLibrary(lm, libRelease, installTask, taskCB); err != nil {
-				return err
-			}
-		} else {
-			if err := downloadLibrary(lm, libRelease, downloadCB, taskCB, "depends"); err != nil {
-				return err
-			}
-			if err := installLibrary(lm, libRelease, installTask, taskCB); err != nil {
-				return err
+			downloadReason = "install"
+			if installTask.ReplacedLib != nil {
+				downloadReason = "upgrade"
 			}
 		}
+		if err := downloadLibrary(lm, libRelease, downloadCB, taskCB, downloadReason); err != nil {
+			return err
+		}
+		if err := installLibrary(lm, libRelease, installTask, taskCB); err != nil {
+			return err
+		}
 	}
 
 	if err := commands.Init(&rpc.InitRequest{Instance: req.Instance}, nil); err != nil {
diff --git a/commands/lib/upgrade.go b/commands/lib/upgrade.go
index 6d166e94d46..b02ed8d5733 100644
--- a/commands/lib/upgrade.go
+++ b/commands/lib/upgrade.go
@@ -73,7 +73,7 @@ func upgrade(instance *rpc.Instance, libs []*installedLib, downloadCB rpc.Downlo
 			NoDeps:      false,
 			NoOverwrite: false,
 		}
-		err := LibraryInstall(context.Background(), libInstallReq, downloadCB, taskCB, "upgrade")
+		err := LibraryInstall(context.Background(), libInstallReq, downloadCB, taskCB)
 		if err != nil {
 			return err
 		}
diff --git a/internal/cli/lib/download.go b/internal/cli/lib/download.go
index d5a317d8531..3616584a91d 100644
--- a/internal/cli/lib/download.go
+++ b/internal/cli/lib/download.go
@@ -60,7 +60,7 @@ func runDownloadCommand(cmd *cobra.Command, args []string) {
 			Name:     library.Name,
 			Version:  library.Version,
 		}
-		_, err := lib.LibraryDownload(context.Background(), libraryDownloadRequest, feedback.ProgressBar(), "download")
+		_, err := lib.LibraryDownload(context.Background(), libraryDownloadRequest, feedback.ProgressBar())
 		if err != nil {
 			feedback.Fatal(tr("Error downloading %[1]s: %[2]v", library, err), feedback.ErrNetwork)
 		}
diff --git a/internal/cli/lib/install.go b/internal/cli/lib/install.go
index 17fcf941bce..bb6ff217fda 100644
--- a/internal/cli/lib/install.go
+++ b/internal/cli/lib/install.go
@@ -130,7 +130,7 @@ func runInstallCommand(cmd *cobra.Command, args []string) {
 			NoDeps:      noDeps,
 			NoOverwrite: noOverwrite,
 		}
-		err := lib.LibraryInstall(context.Background(), libraryInstallRequest, feedback.ProgressBar(), feedback.TaskProgress(), "install")
+		err := lib.LibraryInstall(context.Background(), libraryInstallRequest, feedback.ProgressBar(), feedback.TaskProgress())
 		if err != nil {
 			feedback.Fatal(tr("Error installing %s: %v", libRef.Name, err), feedback.ErrGeneric)
 		}
diff --git a/internal/integrationtest/lib/lib_test.go b/internal/integrationtest/lib/lib_test.go
index b059fdb0f36..37a46940fe0 100644
--- a/internal/integrationtest/lib/lib_test.go
+++ b/internal/integrationtest/lib/lib_test.go
@@ -1518,5 +1518,4 @@ func TestLibQueryParameters(t *testing.T) {
 	require.NoError(t, err)
 	require.Contains(t, string(stdout),
 		"Starting download                             \x1b[36murl\x1b[0m=\"https://downloads.arduino.cc/libraries/github.com/arduino-libraries/WiFi101-0.16.1.zip?query=download\"\n")
-
 }