Skip to content

Support Clientify Analytics PLUS attribution via visitor_key2 - #280

Open
davidperezgar wants to merge 1 commit into
trunkfrom
claude/clientify-cookie-tracking-vyzmpf
Open

Support Clientify Analytics PLUS attribution via visitor_key2#280
davidperezgar wants to merge 1 commit into
trunkfrom
claude/clientify-cookie-tracking-vyzmpf

Conversation

@davidperezgar

Copy link
Copy Markdown
Contributor

Summary

  • Adds visitor_key2 as 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_uuid key in localStorage, which FormsCRM cannot access server-side).
  • Restores support for Clientify's legacy vk tracking cookie, but forwards it automatically as visitor_key on contact creation — no field mapping or per-form hidden field required, since it's a plain HTTP cookie the server can already read.
  • Removes the now-redundant legacy machinery that auto-injected hidden fields into every form plugin (Gravity Forms, Contact Form 7, Elementor, WooCommerce) just to carry that cookie value, along with its dedicated JS file.
  • Bumps plugin version to 4.5.0 and updates the changelog/docs accordingly.

Related issue: #266

Changes

  • includes/crm-library/class-crmlib-clientify.php: added visitor_key2 to the Contacts field list; create_entry() now forwards $_COOKIE['vk'] as visitor_key automatically (Contacts module only, and only when not already set via a mapped field).
  • Removed includes/formscrm-library/class-forms-clientify.php and includes/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 the formscrm_visitorkey_session() session helper, superseded by reading the cookie directly in class-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 the clientify_visitor_key admin-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 for visitor_key2 field mapping, automatic vk cookie forwarding, cookie not overriding an explicitly mapped visitor_key, and the cookie not being forwarded for the Companies module.

Test plan

  • php -l on 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 in tests/API/test-clientify.php).
  • Manual: submit a form with Clientify configured, confirm visitor_key is sent when the vk cookie is present, and visitor_key2 is sent when mapped to a field carrying the Analytics PLUS visitor_uuid.

Generated by Claude Code

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +529 to +530
if ( 'contacts' === $module && empty( $contact['visitor_key'] ) && ! empty( $_COOKIE['vk'] ) ) {
$contact['visitor_key'] = sanitize_text_field( wp_unslash( $_COOKIE['vk'] ) );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Comment on lines +882 to +883
$merge_vars = array();
$field_maps = $this->get_field_map_fields( $feed, 'listFields' );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

This review may be incomplete: some analysis steps could not run due to a temporary API capacity limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants