Klevr Product Documentation logo

Auto Matching Anonymous Gifts

The Online Gift Matching Plugin automatically matches incoming anonymous online gifts to existing contacts in your Dataverse environment.

Online Gift Matching to existing contacts

Overview

The Online Gift Matching Plugin automatically matches incoming anonymous online gifts to existing contacts in your Dataverse environment. When a new online gift is created without a primary contact assigned, this plugin searches for an existing contact that matches specific criteria and automatically associates them.

How It Works

Trigger Conditions

The plugin executes during the PreOperation stage when a new klevr_onlinegift record is being created, and only if:

  1. The online gift's klevr_primarycontactid field is empty/null
  2. The required matching criteria fields are populated on the online gift

Matching Logic

When triggered, the plugin performs the following steps:

  1. Retrieves Configuration - Loads matching rules from the **klevr_OnlineGiftMatchingConfig** environment setting

  2. Determines Sub-Account Context (optional) - Follows a configured path through entity relationships to identify the payment processor sub-account

  3. Searches for Existing Contacts - Queries for active contacts matching:

    • All configured field criteria

    • The same payment processor sub-account identifier (or null if no sub-account)

  4. Selects Best Match - Orders results by creation date (most recent first) and takes the top match

  5. Associates Contact - Sets the matched contact as the primary contact on the online gift

Configuration

Environment Setting Setup

The plugin requires a JSON configuration stored in an environment setting named:

klevr_OnlineGiftMatchingConfig

Configuration Schema

{
  "Enabled": true/false,
"SubAccountPath": "string (optional)",
  "Criteria": {
    "contact_field_name": "onlinegift_field_name",
    "contact_field_name_2": "onlinegift_field_name_2"
  }
}

Enabled

  • Type: Boolean
  • Purpose: Enabled or disables this functionality
  • Default: False

SubAccountPath

  • Type: String (optional)
  • Purpose: Defines a dot-notation path to navigate from the online gift to a payment processor sub-account
  • Format: field.relatedfield.subfield
  • Example: klevr_paymentprocessorid.klevr_subaccountid

This path is used to:

  1. Navigate through entity relationships starting from the online gift
  2. Retrieve the klevr_externalreference value from the klevr_paymentprocessorsubaccount entity
  3. Match only contacts with the same klevr_PaymentProcessorSubAccountIdentifier value

If left empty or if the path doesn't resolve, the plugin will match contacts where klevr_PaymentProcessorSubAccountIdentifier is null.

Criteria

  • Type: Dictionary of field mappings
  • Purpose: Defines which contact fields must match which online gift fields
  • Format: Each key is a contact entity field name; each value is the corresponding online gift field name

Example Configurations

Basic Email Matching

{
  "SubAccountPath": "",
  "Criteria": {
    "emailaddress1": "klevr_email"
  }
}

Matches contacts where the email address matches the online gift's email field.

Multi-Field Matching with Sub-Account (default)

{
  "SubAccountPath": "klevr_paymentprocessorid.klevr_subaccountid",
  "Criteria": {
    "emailaddress1": "klevr_email",
    "lastname": "klevr_lastname",
    "firstname": "klevr_firstname"
  }
}

Matches contacts where:

  • Email, first name, and last name all match
  • The contact's payment processor sub-account matches the online gift's sub-account

Phone Number Matching

{
  "SubAccountPath": "",
  "Criteria": {
    "telephone1": "klevr_phonenumber",
    "emailaddress1": "klevr_email"
  }
}

Matches contacts where both phone and email match.

Behavior & Rules

Active Contacts Only

The plugin only matches against active contacts (StateCode = 0). Inactive or deleted contacts are excluded from matching.

Most Recent Contact Wins

If multiple contacts match all criteria, the plugin selects the most recently created contact (ordered by CreatedOn descending).

Single Match Only

The plugin takes only the top 1 matching contact. It does not create duplicate associations or handle multiple matches.

Sub-Account Isolation

When a sub-account is configured:

  • Contacts are matched only if their klevr_PaymentProcessorSubAccountIdentifier matches the online gift's sub-account
  • This ensures proper Stripe account organization isolation in multi-account scenarios

When no sub-account path is configured or the path resolves to null:

  • Only contacts with a null klevr_PaymentProcessorSubAccountIdentifier are matched
  • This prevents cross-contamination between sub-accounts

No Retroactive Matching

This plugin only executes on Create operations. Existing online gifts without a primary contact are not automatically re-matched.

Use Cases

Returning Donor Recognition

Automatically associate online gifts with existing donor contacts based on email address, reducing manual data entry and improving donor history tracking.

Multi-Tenant Fundraising Platforms

Use sub-account paths to ensure online gifts from different organizations are matched only to contacts within the same organization's sub-account.

Duplicate Contact Prevention

By matching on multiple fields (e.g., email + phone), you can reduce the creation of duplicate contact records when processing online gifts.

Troubleshooting

Contact Not Being Matched

Check:

  1. Is the funvtionality enabled in the Evnironment variable?

  2. Is the klevr_primarycontactid already populated on the online gift?

    • Plugin only runs when this field is null
  3. Do the online gift's fields contain values for all configured criteria?

    • All criteria fields must have matching values
  4. Is the existing contact active?

    • Inactive contacts are excluded from matching
  5. Does the sub-account identifier match?

    • Verify klevr_PaymentProcessorSubAccountIdentifier values align

Enable Tracing:

The plugin includes extensive trace logging. Review the plugin trace log in Dataverse to see:

  • Which sub-account path was used
  • Whether a sub-account ID was resolved
  • Which criteria were applied
  • Whether a match was found

Wrong Contact Being Matched

Check:

  1. Are your matching criteria specific enough?

    • Consider adding more fields to the Criteria configuration
  2. Is the most recently created contact the correct one?

    • The plugin selects the newest matching contact by CreatedOn

Sub-Account Path Not Resolving

Check:

  1. Does the path syntax match the actual field relationship chain?
  2. Are all lookup fields in the chain populated on the online gift?
  3. Do you have read permissions on all entities in the path?

Example Path Validation:

For path klevr_paymentprocessorid.klevr_subaccountid:

  • Online gift must have klevr_paymentprocessorid lookup populated
  • That payment processor must have klevr_subaccountid lookup populated
  • The sub-account record must exist and have klevr_externalreference populated

Deployment Notes

  • The plugin is deployed using the spkl tooling as specified in the repository guidelines
  • Configuration changes (environment setting JSON) do not require plugin redeployment
  • Always test configuration changes in a non-production environment first
  • klevr_onlinegift: The source entity where online gifts are created
  • contact: The target entity where existing customers are stored
  • klevr_paymentprocessorsubaccount: Used for sub-account identification and isolation

Security Considerations

This plugin uses an elevated service context (_ElevatedService) to:

  • Retrieve sub-account information
  • Query for matching contacts

This ensures matching works regardless of the creating user's permissions. Ensure your security model accounts for this behavior.


Quick Start Checklist

  • Create environment setting named klevr_OnlineGiftMatchingConfig
  • Define JSON configuration with matching criteria
  • Optionally configure sub-account path for multi-tenant scenarios
  • Deploy the plugin (or verify it's already deployed)
  • Test with a sample online gift record
  • Review plugin trace logs to verify matching behavior
  • Adjust criteria as needed based on results

What if my customer has more demanding criteria?

Speak to us to see if we can extend the current functionality in a generic way to cater for your requirements, or alternatively you will need to disable this plugin through the environment variable configuration and create your own plugin for matching. Speak to us to get the source code for our version as a starting point for yours.

Last updated on