diff --git a/src/Pid/App.config b/src/Pid/App.config
index 689f53de03d7e8baf0315a7afc04af319b060b3f..edf036989502f0c247a217530753edf79f87c0a6 100644
--- a/src/Pid/App.config
+++ b/src/Pid/App.config
@@ -168,11 +168,15 @@
       </dependentAssembly>
       <dependentAssembly>
         <assemblyIdentity name="Coscine.Database" publicKeyToken="767d77427707b70a" culture="neutral" />
-        <bindingRedirect oldVersion="0.0.0.0-1.27.0.0" newVersion="1.27.0.0" />
+        <bindingRedirect oldVersion="0.0.0.0-1.28.0.0" newVersion="1.28.0.0" />
       </dependentAssembly>
       <dependentAssembly>
         <assemblyIdentity name="Coscine.Database.T4" publicKeyToken="84b4c404a0696261" culture="neutral" />
-        <bindingRedirect oldVersion="0.0.0.0-1.27.0.0" newVersion="1.27.0.0" />
+        <bindingRedirect oldVersion="0.0.0.0-1.28.0.0" newVersion="1.28.0.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="Coscine.Logging" publicKeyToken="e1ed402bc3f6525e" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-1.3.0.0" newVersion="1.3.0.0" />
       </dependentAssembly>
     </assemblyBinding>
   </runtime>
diff --git a/src/Pid/Controllers/PidController.cs b/src/Pid/Controllers/PidController.cs
index af523e69edd74e98c2a1de281d108baedacc5de6..f8e2665e2a7dd9fca60696c19f20085721390162 100644
--- a/src/Pid/Controllers/PidController.cs
+++ b/src/Pid/Controllers/PidController.cs
@@ -1,20 +1,18 @@
 using Coscine.Database.Models;
 using Coscine.Database.ReturnObjects;
-using Coscine.ApiCommons;
-using Coscine.ApiCommons.Factories;
 using Microsoft.AspNetCore.Mvc;
 using System;
 using System.Linq;
 using Coscine.Configuration;
-using Microsoft.AspNetCore.Authorization;
 using Newtonsoft.Json.Linq;
 using Coscine.Database.DataModel;
-using Coscine.Database.Util;
 using Coscine.Logging;
 using Microsoft.Extensions.Logging;
 using Coscine.Api.Pid.Models;
 using Coscine.Action;
 using Coscine.Action.EventArgs;
+using System.Collections.Generic;
+using System.Text;
 
 namespace Coscine.Api.Pid.Controllers
 {
@@ -24,8 +22,11 @@ namespace Coscine.Api.Pid.Controllers
     public class PidController : Controller
     {
         private readonly ResourceModel _resourceModel;
+        private readonly ProjectModel _projectModel;
         private readonly IConfiguration _configuration;
         private readonly Emitter _emitter;
+        private readonly CoscineLogger _coscineLogger;
+        private readonly AnalyticsLogObject _analyticsLogObject;
 
         /// <summary>
         /// PidController constructor for contacting the pid owner.
@@ -35,6 +36,9 @@ namespace Coscine.Api.Pid.Controllers
             _configuration = Program.Configuration;
             _emitter = new Emitter(this._configuration);
             _resourceModel = new ResourceModel();
+            _projectModel = new ProjectModel();
+            _coscineLogger = new CoscineLogger(logger);
+            _analyticsLogObject = new AnalyticsLogObject();
         }
 
         /// <summary>
@@ -45,7 +49,18 @@ namespace Coscine.Api.Pid.Controllers
         [HttpPost("[controller]/sendMailToOwner")]
         public IActionResult SendMailToOwner([FromBody] MessageObject messageObject)
         {
-            var resource = _resourceModel.GetById(new Guid(messageObject.Guid));
+            var resource = _resourceModel.GetById(new Guid(messageObject.Pid));
+            var project = _projectModel.GetById(new Guid(messageObject.Pid));
+
+            string resourceId = null;
+            string projectId = null;
+            string applicationProfile = null;
+            LicenseObject license = null;
+            IEnumerable<DisciplineObject> disciplines = null;
+            IEnumerable<OrganizationObject> organizations = null;
+            string visibility = null;
+            string externalInfo = null;
+
             var user = new User()
             {
                 DisplayName = messageObject.Name,
@@ -53,12 +68,32 @@ namespace Coscine.Api.Pid.Controllers
             };
             var placeholder = new JObject()
             {
-                ["resourceName"] = resource.DisplayName,
                 ["requesterName"] = messageObject.Name,
                 ["requesterMail"] = messageObject.Email,
                 ["requestMessage"] = messageObject.Message,
                 ["pid"] = messageObject.Pid
             };
+
+            if (resource != null)
+            {
+                placeholder["resourceName"] = resource.DisplayName;
+
+                ResourceObject resourceObject = _resourceModel.CreateReturnObjectFromDatabaseObject(resource);
+                ProjectResourceModel projectResourceModel = new ProjectResourceModel();
+
+                resourceId = resource.Id.ToString();
+                applicationProfile = resourceObject.ApplicationProfile;
+                license = resourceObject.License;
+                project = _projectModel.GetById(
+                    projectResourceModel.GetAllWhere((resourceProject) => (resourceProject.ResourceId == resource.Id))
+                    .First().ProjectId);
+            }
+            else
+            {
+                placeholder["projectName"] = project.DisplayName;
+                projectId = project.Id.ToString();
+            }
+
             _emitter.EmitPIDOwnerContact(new PIDEventArgs(_configuration)
             {
                 Requester = user,
@@ -66,7 +101,91 @@ namespace Coscine.Api.Pid.Controllers
                 SentCopy = messageObject.SendCopy,
                 Placeholder = placeholder
             });
+
+            ProjectObject projectObject = _projectModel.CreateReturnObjectFromDatabaseObject(project);
+            projectId = project.Id.ToString();
+            disciplines = projectObject.Disciplines;
+            organizations = projectObject.Organizations;
+            visibility = projectObject.Visibility.DisplayName;
+            externalInfo = messageObject.Email;
+            
+            RoleModel rolesModel = new RoleModel();
+            ProjectRoleModel projectRoleModel = new ProjectRoleModel();
+            Guid ownerId = rolesModel.GetAllWhere((role) => (role.DisplayName == "owner")).First().Id;
+            var projectOwners = projectRoleModel.GetAllWhere((projectRole) => (projectRole.RoleId == ownerId && projectRole.ProjectId == project.Id));
+
+            LogAnalytics("PID Enquiry", resourceId, user, projectId, applicationProfile, license, disciplines, organizations, visibility, projectOwners, externalInfo);
+
             return Json(new JObject { ["status"] = "ok" });
         }
+
+
+        private void LogAnalytics(string operation,
+            string resourceId = null,
+            User user = null,
+            string projectId = null,
+            string applicationProfile = null,
+            LicenseObject license = null,
+            IEnumerable<DisciplineObject> disciplines = null,
+            IEnumerable<OrganizationObject> organizations = null,
+            string visibility = null,
+            IEnumerable<ProjectRole> projectOwners = null,
+            string externalInfo = null
+        )
+        {
+            if (CoscineLoggerConfiguration.IsLogLevelActivated(LogType.Analytics))
+            {
+
+                List<string> organizationsList = new List<string>();
+                List<string> disciplinesList = new List<string>();
+
+                _analyticsLogObject.ProjectId = projectId;
+                _analyticsLogObject.Type = "Action";
+                _analyticsLogObject.Operation = operation;
+                _analyticsLogObject.ApplicationsProfile = applicationProfile;
+                _analyticsLogObject.ResourceId = resourceId; 
+                _analyticsLogObject.Visibility = visibility;
+                
+                if (disciplines != null && disciplines.Count() > 0)
+                {
+                    foreach (var discipline in disciplines)
+                    {
+                        disciplinesList.Add(discipline.DisplayNameEn);
+                    }
+                    _analyticsLogObject.Disciplines = disciplinesList;
+                }
+                if (organizations != null && organizations.Count() > 0)
+                {
+                    foreach (var organization in organizations)
+                    {
+                        organizationsList.Add(organization.Url);
+                    }
+                    _analyticsLogObject.Organizations = organizationsList;
+                }
+                if (projectOwners != null)
+                {
+                    List<string> ownerIds = new List<string>();
+                    foreach(var projectOwner in projectOwners)
+                    {
+                        ownerIds.Add(projectOwner.UserId.ToString());
+                    }
+                    _analyticsLogObject.UserList = ownerIds;
+                }
+                if (license != null)
+                {
+                    _analyticsLogObject.License = license.DisplayName;
+                }
+                /*if (externalInfo != null) // this was for the externalInformation column, original intended use to store the hashed email adress of the requester
+                {
+                    StringBuilder stringBuilder = new StringBuilder();
+                    foreach (byte b in externalInfo)
+                        stringBuilder.Append(b.ToString("X2"));
+                    externalInfo = stringBuilder.ToString();
+                    _analyticsLogObject.ExternalInfo = externalInfo;
+                }*/
+
+                _coscineLogger.AnalyticsLog(_analyticsLogObject);
+            }
+        }
     }
 }
diff --git a/src/Pid/Pid.csproj b/src/Pid/Pid.csproj
index 9978a9d14b09feebfd4f9575f41125f6ea373932..f48bb2a73b5b574c9c4e8cc2b3922a10f17d8187 100644
--- a/src/Pid/Pid.csproj
+++ b/src/Pid/Pid.csproj
@@ -54,23 +54,23 @@
     <Reference Include="Coscine.Action, Version=1.17.0.0, Culture=neutral, processorArchitecture=AMD64">
       <HintPath>..\packages\Coscine.Action.1.17.0\lib\net461\Coscine.Action.dll</HintPath>
     </Reference>
-    <Reference Include="Coscine.ApiCommons, Version=1.11.0.0, Culture=neutral, PublicKeyToken=af4c1345df96546b, processorArchitecture=MSIL">
-      <HintPath>..\packages\Coscine.ApiCommons.1.11.0\lib\net461\Coscine.ApiCommons.dll</HintPath>
+    <Reference Include="Coscine.ApiCommons, Version=1.12.0.0, Culture=neutral, PublicKeyToken=af4c1345df96546b, processorArchitecture=MSIL">
+      <HintPath>..\packages\Coscine.ApiCommons.1.12.0-topic-1221-loggi0001\lib\net461\Coscine.ApiCommons.dll</HintPath>
     </Reference>
     <Reference Include="Coscine.Configuration, Version=1.5.0.0, Culture=neutral, PublicKeyToken=ce3d7a32d7dc1e5a, processorArchitecture=MSIL">
       <HintPath>..\packages\Coscine.Configuration.1.5.0\lib\net461\Coscine.Configuration.dll</HintPath>
     </Reference>
-    <Reference Include="Coscine.Database, Version=1.27.0.0, Culture=neutral, PublicKeyToken=767d77427707b70a, processorArchitecture=MSIL">
-      <HintPath>..\packages\Coscine.Database.1.27.0\lib\net461\Coscine.Database.dll</HintPath>
+    <Reference Include="Coscine.Database, Version=1.28.0.0, Culture=neutral, PublicKeyToken=767d77427707b70a, processorArchitecture=MSIL">
+      <HintPath>..\packages\Coscine.Database.1.28.0-topic-1221-loggi0005\lib\net461\Coscine.Database.dll</HintPath>
     </Reference>
-    <Reference Include="Coscine.Database.T4, Version=1.27.0.0, Culture=neutral, PublicKeyToken=84b4c404a0696261, processorArchitecture=MSIL">
-      <HintPath>..\packages\Coscine.Database.1.27.0\lib\net461\Coscine.Database.T4.dll</HintPath>
+    <Reference Include="Coscine.Database.T4, Version=1.28.0.0, Culture=neutral, PublicKeyToken=84b4c404a0696261, processorArchitecture=MSIL">
+      <HintPath>..\packages\Coscine.Database.1.28.0-topic-1221-loggi0005\lib\net461\Coscine.Database.T4.dll</HintPath>
     </Reference>
     <Reference Include="Coscine.JwtHandler, Version=1.2.0.0, Culture=neutral, PublicKeyToken=aaacf41df3a6253c, processorArchitecture=MSIL">
       <HintPath>..\packages\Coscine.JwtHandler.1.2.0\lib\net461\Coscine.JwtHandler.dll</HintPath>
     </Reference>
-    <Reference Include="Coscine.Logging, Version=1.2.0.0, Culture=neutral, PublicKeyToken=e1ed402bc3f6525e, processorArchitecture=MSIL">
-      <HintPath>..\packages\Coscine.Logging.1.2.0\lib\net461\Coscine.Logging.dll</HintPath>
+    <Reference Include="Coscine.Logging, Version=1.3.0.0, Culture=neutral, PublicKeyToken=e1ed402bc3f6525e, processorArchitecture=MSIL">
+      <HintPath>..\packages\Coscine.Logging.1.3.0-topic-1221-loggi0003\lib\net461\Coscine.Logging.dll</HintPath>
     </Reference>
     <Reference Include="Coscine.ProxyApi, Version=1.3.0.0, Culture=neutral, processorArchitecture=MSIL">
       <HintPath>..\packages\Coscine.ProxyApi.1.3.0\lib\net461\Coscine.ProxyApi.dll</HintPath>
diff --git a/src/Pid/packages.config b/src/Pid/packages.config
index 3818c1353e265c764f753f006c20d828a8045a93..f9aba5126952f233c2efb8b15c2632b8d1dfc9c4 100644
--- a/src/Pid/packages.config
+++ b/src/Pid/packages.config
@@ -2,11 +2,11 @@
 <packages>
   <package id="Consul" version="0.7.2.6" targetFramework="net461" />
   <package id="Coscine.Action" version="1.17.0" targetFramework="net461" />
-  <package id="Coscine.ApiCommons" version="1.11.0" targetFramework="net461" />
+  <package id="Coscine.ApiCommons" version="1.12.0-topic-1221-loggi0001" targetFramework="net461" />
   <package id="Coscine.Configuration" version="1.5.0" targetFramework="net461" />
-  <package id="Coscine.Database" version="1.27.0" targetFramework="net461" />
+  <package id="Coscine.Database" version="1.28.0-topic-1221-loggi0005" targetFramework="net461" />
   <package id="Coscine.JwtHandler" version="1.2.0" targetFramework="net461" />
-  <package id="Coscine.Logging" version="1.2.0" targetFramework="net461" />
+  <package id="Coscine.Logging" version="1.3.0-topic-1221-loggi0003" targetFramework="net461" />
   <package id="Coscine.ProxyApi" version="1.3.0" targetFramework="net461" />
   <package id="EntityFramework" version="6.4.4" targetFramework="net461" />
   <package id="linq2db" version="3.1.1" targetFramework="net461" />