Using Gravity Forms ‘gform_activecampaign_contact_pre_sync’ PHP filter

The gform_activecampaign_contact_pre_sync filter allows you to modify contact properties before the contact_sync request is sent to the ActiveCampaign API.

Usage

To apply the filter for all ActiveCampaign feeds, use the following code:

add_filter('gform_activecampaign_contact_pre_sync', 'your_function_name', 10, 4);

To limit the scope of the filter to a specific form, append the form ID to the hook name like this:

add_filter('gform_activecampaign_contact_pre_sync_5', 'your_function_name', 10, 4);

Parameters

  • $contact (array): The contact properties. See the ActiveCampaign API documentation for the full list of accepted properties.
  • $entry (Entry Object): The entry currently being processed.
  • $form (Form Object): The form object the current entry was created from.
  • $feed (Feed Object): The feed which is currently being processed.

More information

See Gravity Forms Docs: gform_activecampaign_contact_pre_sync

This filter was added in ActiveCampaign 1.3.5.

Examples

Add IP Address Property to Contact

This example demonstrates how to add the IP address (ip4) property to the contact.

add_filter('gform_activecampaign_contact_pre_sync', function($contact, $entry, $form, $feed) {
    $contact['ip4'] = rgar($entry, 'ip');
    return $contact;
}, 10, 4);

Set Custom Field Value

This example shows how to set a custom field value for the contact before syncing with ActiveCampaign.

add_filter('gform_activecampaign_contact_pre_sync', function($contact, $entry, $form, $feed) {
    $contact['fieldValues'][] = array(
        'field' => 'CUSTOM_FIELD_ID',
        'value' => 'Custom Value'
    );
    return $contact;
}, 10, 4);

Modify Contact’s First Name

This example demonstrates how to modify the contact’s first name before syncing with ActiveCampaign.

add_filter('gform_activecampaign_contact_pre_sync', function($contact, $entry, $form, $feed) {
    $contact['firstName'] = 'Modified ' . $contact['firstName'];
    return $contact;
}, 10, 4);

Remove Contact’s Phone Number

This example shows how to remove the contact’s phone number before syncing with ActiveCampaign.

add_filter('gform_activecampaign_contact_pre_sync', function($contact, $entry, $form, $feed) {
    unset($contact['phone']);
    return $contact;
}, 10, 4);

Add Contact to a Specific List

This example demonstrates how to add the contact to a specific list before syncing with ActiveCampaign.

add_filter('gform_activecampaign_contact_pre_sync', function($contact, $entry, $form, $feed) {
    $contact['list'][] = array(
        'list' => 'LIST_ID',
        'status' => 1
    );
    return $contact;
}, 10, 4);

Note: Replace LIST_ID with the actual ID of the list you want to add the contact to.