__( 'Customer.io', 'advanced-form-integration' ), 'tasks' => array( 'add_people' => __( 'Add People', 'advanced-form-integration' ), ), ); return $actions; } add_filter( 'adfoin_settings_tabs', 'adfoin_customerio_settings_tab', 10, 1 ); function adfoin_customerio_settings_tab( $providers ) { $providers['customerio'] = __( 'Customer.io', 'advanced-form-integration' ); return $providers; } add_action( 'adfoin_settings_view', 'adfoin_customerio_settings_view', 10, 1 ); function adfoin_customerio_settings_view( $current_tab ) { if ( $current_tab != 'customerio' ) { return; } $title = __( 'Customer.io', 'advanced-form-integration' ); $key = 'customerio'; $arguments = wp_json_encode( array( 'platform' => $key, 'fields' => array( array( 'key' => 'api_key', 'label' => __( 'API Key', 'advanced-form-integration' ), 'hidden' => true ) ) ) ); $instructions = __( '
  1. Log in to your Customer.io account.
  2. Navigate to People > Add People > Customer.io API.
  3. Copy the API Key but keep the this page open.
  4. Save the API Key into AFI > Settings > Customer.io.
  5. Create a basic integration and submit form to test it.
  6. Click on the Test connection button in the opened page.
  7. A success message will be displayed if the connection is successful.
', 'advanced-form-integration' ); echo adfoin_platform_settings_template( $title, $key, $arguments, $instructions ); } add_action('wp_ajax_adfoin_get_customerio_credentials', 'adfoin_get_customerio_credentials', 10, 0); function adfoin_get_customerio_credentials() { adfoin_verify_nonce(); $all_credentials = adfoin_read_credentials('customerio'); wp_send_json_success($all_credentials); } add_action('wp_ajax_adfoin_save_customerio_credentials', 'adfoin_save_customerio_credentials', 10, 0); function adfoin_save_customerio_credentials() { adfoin_verify_nonce(); $platform = sanitize_text_field( wp_unslash( $_POST['platform'] ) ); if ('customerio' == $platform) { $data = adfoin_array_map_recursive('sanitize_text_field', $_POST['data']); adfoin_save_credentials($platform, $data); } wp_send_json_success(); } function adfoin_customerio_credentials_list() { $html = ''; $credentials = adfoin_read_credentials('customerio'); foreach ($credentials as $option) { $html .= ''; } echo $html; } add_action( 'adfoin_action_fields', 'adfoin_customerio_action_fields' ); function adfoin_customerio_action_fields() { ?> 30, 'method' => $method, 'headers' => array( 'Content-Type' => 'application/json', 'Accept' => 'application/json', 'User-Agent' => 'Advanced Form Integration', 'Authorization' => 'Basic '. base64_encode( $api_key .':') ) ); if( 'POST' == $method || 'PUT' == $method ) { $args['body'] = wp_json_encode( $data ); } $response = wp_remote_request( $url, $args ); if( $record ) { adfoin_add_to_log( $response, $url, $args, $record ); } return $response; } add_action( 'adfoin_customerio_job_queue', 'adfoin_customerio_job_queue', 10, 1 ); function adfoin_customerio_job_queue( $data ) { adfoin_customerio_send_data( $data['record'], $data['posted_data'] ); } /* * Handles sending data to customerio API */ function adfoin_customerio_send_data( $record, $posted_data ) { $record_data = json_decode( $record['data'], true ); // Conditional logic check if ( adfoin_check_conditional_logic( $record_data['action_data']['cl'] ?? array(), $posted_data ) ) { return; } $data = $record_data['field_data']; $task = $record['task']; if ( $task === 'add_people' ) { $user_id = ! empty( $data['userId'] ) ? adfoin_get_parsed_values( $data['userId'], $posted_data ) : ''; $email = ! empty( $data['email'] ) ? trim( adfoin_get_parsed_values( $data['email'], $posted_data ) ) : ''; $traits = [ 'email' => $email, 'type' => 'identify' ]; if ( ! empty( $data['name'] ) ) { $traits['name'] = adfoin_get_parsed_values( $data['name'], $posted_data ); } foreach ( $data as $key => $value ) { if ( ! in_array( $key, ['userId','email','name'], true ) && ! empty( $value ) ) { $traits[$key] = adfoin_get_parsed_values( $value, $posted_data ); } } $payload = ['traits' => $traits]; if ( ! empty( $user_id ) ) { $payload['userId'] = $user_id; } else { $payload['anonymousId'] = wp_generate_uuid4(); } adfoin_customerio_request( 'identify', 'POST', $payload, $record ); } return; }