WP Residence Help WP Residence Help

  • WpEstate
  • WPRESIDENCE
  • Video Tutorials
  • Client Support
  • API
Home / 13. WPResidence / WPEstate CRM / WPResidence CRM Viewed Listings Tracking — Developer Reference

WPResidence CRM Viewed Listings Tracking — Developer Reference

13 views 0

Developer documentation for the viewed-listings tracker in the WPResidence real estate CRM. Lives in libs/viewed-functions.php.

Storage – wp_wpresidence_crm_viewed_listings

Columns: id (PK), contact_id, listing_id, viewed_at. No UNIQUE constraint, so multiple views are permitted. Indexes on contact_id, listing_id, and composite (contact_id, viewed_at).

Contact Resolution

wpestate_crm_resolve_contact_id() returns the current contact ID using:

  1. Cookie priority: reads wpestate_crm_contact_id cookie and validates the value exists in the contacts table.
  2. Logged-in user fallback: if the user is logged in, looks up a contact row by wp_user_id; if not found, then by user_id.
  3. Returns 0 if nothing resolves.

Cookie Setting

Set by libs/auto-create.php after a contact is created or matched by a form submission:

  • Name: wpestate_crm_contact_id
  • Lifetime: 1 year (YEAR_IN_SECONDS).
  • Flags: HttpOnly, SameSite=Lax, Secure on HTTPS.
  • Set only when HTTP headers have not been sent.

Tracking Hook

Registered on template_redirect:

wpestate_crm_track_viewed_listing()

Flow:

  1. If not on a single estate_property page, return.
  2. Resolve contact ID via wpestate_crm_resolve_contact_id(). If 0, return.
  3. Insert a row into wp_wpresidence_crm_viewed_listings.
  4. Record a viewed_listing activity via wpestate_crm_record_activity_v2() with meta: {listing_id, listing_title, listing_price}.
  5. Fire do_action(‘wpestate_crm_after_viewed_listing’, $contact_id, $listing_id).

Helpers

Function Returns
wpestate_crm_resolve_contact_id() Current contact ID or 0
wpestate_crm_get_viewed_count_by_contact($contact_id) Int – total views for that contact

AJAX Endpoint

Action Nonce
wpestate_crm_get_viewed_listings wpestate_crm_nonce (security param)

GET params: contact_id. Returns JSON with listings (array of objects with id, listing_id, title, thumbnail, price, viewed_at, permalink) and total.

Downstream Automation Hook

The wpestate_crm_after_viewed_listing action is consumed by the event-based dispatcher in libs/automations-cron.php. Default rule 26 (3+ views in 24 hours → create follow-up task) listens on this event and evaluates the computed viewed_listing_count_last_24h condition.

Retention

There is no automatic purging. For sites that care about GDPR minimization, add a cron job to delete rows older than N months. The table has a viewed_at index, so the delete can be done efficiently with DELETE FROM wp_wpresidence_crm_viewed_listings WHERE viewed_at < DATE_SUB(NOW(), INTERVAL N DAY).

Privacy & GDPR

The tracking cookie must be disclosed in the site’s privacy policy. Consider gating the cookie behind a consent banner in jurisdictions that require prior consent. Contact deletion requests should also purge viewed-listing rows keyed on the contact’s contact_id.

Extending

  • To track non-property pages, add a similar hook on template_redirect for your custom post types and write rows into the same table, using listing_id to mean the entity ID of the viewed item.
  • To add a session-level cookie instead of a persistent one, override the cookie write in a child plugin by running your logic earlier in the request lifecycle.
13. WPResidence / WPEstate CRM

Related Articles

  • WPResidence CRM Security Model — Developer Reference
  • CRM Security and Data Privacy
  • WPResidence CRM Installation and Updates — Developer Reference
  • Installing and Updating the WPResidence CRM

WP Residence Documentation

  • 01. Getting Started
    • How to Get Support
    • Get your buyer license code.
    • Use SSL / https
    • Server / Theme Requirements
  • 02. Installation & Setup
  • 03. Installation FAQ
  • 06. Search & Filtering
    • Advanced Search Display Settings
    • Advanced Search Form
    • Geolocation Search for Half Map
    • Save Search Theme Options
    • Advanced Search Colors
  • 09. Agent, Agency & Developers
  • 08. Property Pages & Layouts
  • 07. Property Lists, Categories & Archive
  • 14. WPResidence Elementor Studio
  • 10. Blog Posts & Blog List
  • 11. Shortcodes
    • Contact Form
    • Featured Agency/Developer
    • Membership Packages
    • Testimonials
    • Google Map with Property Marker
    • Listings per Agent, Agency or Developer
    • Display Categories
    • Agent List
    • Recent Items Slider
    • Recent items
    • List Properties or Articles by ID
    • Featured Agent
    • Featured Article
    • Featured Property
    • Login & Register Form
    • Icon Content Box Shortcode
  • 12. Widgets
  • 04. Theme Options & Global Settings
    • General Settings
    • User Types Settings
    • Appearance
    • Logos & Favicon
    • Header
    • Footer Style and Colors
    • Price & Currency
    • Property Custom Fields
    • Features & Amenities
    • Listing Labels
    • Theme Slider
    • Permalinks
    • Splash Page
    • Social & Contact
    • Map Settings
    • Pin Management
    • How read from file works
    • General Design Settings
    • Custom Colors Settings
    • Header Design & Colors
    • Mobile Menu Colors
    • User Dashboard Colors
    • Print PDF Design
    • Property, Agent, Blog Lists Design Settings
    • Sidebar Widget Design
    • Font management
    • How to add custom CSS
    • Custom Property Card Unit – Beta version
    • Email Management
    • Import & Export theme options
    • reCaptcha settings
    • YELP API Integration
    • iHomefinder Optima Express IDX
    • MEMBERSHIP & PAYMENT Settings
    • Property Submission Page
    • PayPal Setup
    • Stripe Setup
    • Wire Transfer Payment Method
  • 20. Translations & Languages
  • 26. FAQ
  • 10. Pages
  • 11. Header
  • 12. Footer
  • 05. Maps & Location Settings
  • 18. Payments & Monetization
  • Plugins
    • 19. Included Plugins
    • 22. Third Party Plugins – IDX Compatibility
    • 21. Third-Party Plugins – Multi-Language
    • 23. Third party Plugins – Other
  • Technical
    • 24. Technical how to | Custom Code Required
    • 25. Technical: Child Theme

Join Us On

Powered by WP Estate - All Rights Reserved
  • WpEstate
  • WPRESIDENCE
  • Video Tutorials
  • Client Support
  • API