Is there any hook that can be used for logging contact views? We need to create report for that and first of course need to put that information to database.
-
I am unclear on what you are asking (but that might be me)?– ErikH - CiviCooPFeb 21, 2019 at 13:12
-
I just want to write log every time when user views some contact. There is logging for edit or delete but not for view.– Teemu ParkkinenFeb 21, 2019 at 14:29
-
Jitendra has provided an approach for you to log contact summary views, but be aware that you can get contact information in many ways besides the viewing a contact summary. What is the purpose of the report? It will show you who viewed a contact summary page, not who viewed information about a contact.– Aidan ♦Feb 21, 2019 at 22:43
-
Aidan yes that's a little problem because we need to know who have seen contact informations in every way.– Teemu ParkkinenApr 26, 2019 at 17:02
1 Answer
With contact view, I guess you mean when a contact summary page for a specific id is loaded you want me to increment a count number and store it in DB to display it in the report.
Currently, there is no such feature in core civicrm. You need to add a custom extension to add this functionality. See more details to build a simple ext at https://docs.civicrm.org/dev/en/latest/extensions/civix/. Some basic steps would be -
Add a custom field to extend Contact eg
View Count
.Use
hook_civicrm_summary
to increment the value of this field for a specific contact ID.You can use this custom field to show on any report provided by civicrm.
-
1Yes. Thank you, so the summary is the right hook for that. That doesn't work in search results but I think its enough for now. Feb 21, 2019 at 16:14
-
1And no, we don't need the count. We need information about who has seen that contact and when. Feb 21, 2019 at 16:15