Support Clientify Analytics PLUS attribution via visitor_key2 - #280
Support Clientify Analytics PLUS attribution via visitor_key2#280davidperezgar wants to merge 1 commit into
Conversation
Adds visitor_key2 as a mappable Contacts field for Clientify so contacts can be attributed to Analytics PLUS pixel visits (value comes from the __<pixel_key>_visitor_uuid localStorage key, captured client-side). Also removes the legacy per-form-plugin hidden-field injection used to carry the older vk tracking cookie (Gravity Forms, Contact Form 7, Elementor, WooCommerce) and instead forwards that cookie automatically as visitor_key on contact creation, since it travels with the request and can be read server-side without any field or JS. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Mfjh1ZNTT9BALXVPD2kL92
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 228507fb0f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if ( 'contacts' === $module && empty( $contact['visitor_key'] ) && ! empty( $_COOKIE['vk'] ) ) { | ||
| $contact['visitor_key'] = sanitize_text_field( wp_unslash( $_COOKIE['vk'] ) ); |
There was a problem hiding this comment.
Persist the visitor key before scheduling retries
When the initial Clientify request fails, this cookie value exists only in the local $contact payload; the callers pass their original $merge_vars to formscrm_alert_error(), so FORMSCRM_Error_Log::insert_log() stores no visitor_key. The scheduled path in FORMSCRM_Error_Log::retry_failed_entry() later reconstructs the request from that stored lead data under WP-Cron, where the submitter's cookie is unavailable, causing a successful retry to silently lose attribution (and a manual admin resend can instead attach the admin's own vk cookie). Add the captured value to the data persisted for retries rather than reading the current request's cookie anew on every create_entry() call.
Useful? React with 👍 / 👎.
| $merge_vars = array(); | ||
| $field_maps = $this->get_field_map_fields( $feed, 'listFields' ); |
There was a problem hiding this comment.
Preserve the visitor key for asynchronous Gravity Forms feeds
Gravity Forms attribution now fails on ordinary submissions because this add-on sets $_async_feed_processing = true, so process_feed() normally runs in a background request that has no access to the submitter's vk cookie. The removed hidden field previously stored the value in the Gravity Forms entry, and the deleted extraction logic added that stored value to $merge_vars; after dropping it here, CRMLIB_Clientify::create_entry() sees no cookie and sends no visitor_key. Keep capturing the value during the browser request and reading it from the persisted entry when the asynchronous feed executes.
Useful? React with 👍 / 👎.
Summary
visitor_key2as a mappable field for Clientify Contacts, so form submissions can be linked to the visit tracked by the Analytics PLUS pixel (value read client-side from the__<pixel_key>_visitor_uuidkey inlocalStorage, which FormsCRM cannot access server-side).vktracking cookie, but forwards it automatically asvisitor_keyon contact creation — no field mapping or per-form hidden field required, since it's a plain HTTP cookie the server can already read.Related issue: #266
Changes
includes/crm-library/class-crmlib-clientify.php: addedvisitor_key2to the Contacts field list;create_entry()now forwards$_COOKIE['vk']asvisitor_keyautomatically (Contacts module only, and only when not already set via a mapped field).includes/formscrm-library/class-forms-clientify.phpandincludes/formscrm-library/js/clientify-field.js(auto hidden-field injection for GF/CF7/Elementor/WooCommerce + cookie-reading JS).includes/formscrm-library/loader.php: dropped the now-deleted require.includes/formscrm-library/helpers-library-crm.php: removed theformscrm_visitorkey_session()session helper, superseded by reading the cookie directly inclass-crmlib-clientify.php.includes/formscrm-library/class-elementor.php: removed the raw$_POST['visitor_key']fallback handling, no longer needed.includes/formscrm-library/class-gravityforms.php: removed theclientify_visitor_keyadmin-label special case tied to the deleted auto-field-creation code.readme.txt: updated Clientify settings docs and changelog.tests/API/test-clientify.php: added coverage forvisitor_key2field mapping, automaticvkcookie forwarding, cookie not overriding an explicitly mappedvisitor_key, and the cookie not being forwarded for the Companies module.Test plan
php -lon all changed files (no syntax errors).composer lint/composer phpstan(could not run in this session — GitHub API auth issue when installing dev dependencies through this sandbox's network proxy; should run cleanly in CI).composer test(same environment limitation as above; new tests follow the existing mock/assert conventions intests/API/test-clientify.php).visitor_keyis sent when thevkcookie is present, andvisitor_key2is sent when mapped to a field carrying the Analytics PLUSvisitor_uuid.Generated by Claude Code