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 - CiviCooP Feb 21 '19 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 Parkkinen Feb 21 '19 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 '19 at 22:43
  • Aidan yes that's a little problem because we need to know who have seen contact informations in every way. – Teemu Parkkinen Apr 26 '19 at 17:02

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.

| improve this answer | |
  • 1
    Yes. 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. – Teemu Parkkinen Feb 21 '19 at 16:14
  • 1
    And no, we don't need the count. We need information about who has seen that contact and when. – Teemu Parkkinen Feb 21 '19 at 16:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.