• Resolved kartiksadadiya

    (@kartiksadadiya)


    I want to modify the initial subscription status of the email when some one visits the site, And i don’t see any hook for the same. For example when some one visits the website and add an email just adding the email not doing any click or anything it fires the ajax call which adds the user to the audience list in omnisend – https://prnt.sc/XalFvjDdYKkB

    After digging in the code found that it coming from this code

    <?php
    /**
    * Omnisend AJAX Functions
    *
    * @package OmnisendPlugin
    */

    defined( 'ABSPATH' ) || exit;

    add_action( 'wp_ajax_omnisend_identify', 'omnisend_hook_omnisend_ajax_save_email' );
    add_action( 'wp_ajax_nopriv_omnisend_identify', 'omnisend_hook_omnisend_ajax_save_email' );

    function omnisend_hook_omnisend_ajax_save_email() {
    check_ajax_referer( 'omnisend-front-script-nonce' );

    Omnisend_Logger::hook();
    $email = ! empty( $_GET['email'] ) ? sanitize_email( wp_unslash( $_GET['email'] ) ) : '';
    $contact_id = ! empty( $_GET['contact_id'] ) ? sanitize_text_field( wp_unslash( $_GET['contact_id'] ) ) : '';
    Omnisend_Logger::debug( "omnisend_hook_omnisend_ajax_save_email - received email: $email, contact_id: $contact_id" );
    Omnisend_Ajax::identify_by_email( $email, $contact_id );

    exit;
    }

    add_action( 'wp_ajax_omnisend_track_started_checkout_event', 'omnisend_track_started_checkout_event' );
    add_action( 'wp_ajax_nopriv_omnisend_track_started_checkout_event', 'omnisend_track_started_checkout_event' );

    function omnisend_track_started_checkout_event() {
    check_ajax_referer( 'omnisend-checkout-script-nonce' );

    Omnisend_Logger::hook();
    $email = ! empty( $_GET['email'] ) ? sanitize_email( wp_unslash( $_GET['email'] ) ) : '';
    Omnisend_Logger::debug( "omnisend_track_started_checkout_event - received email: $email" );
    Omnisend_Cart_Event::started_checkout( $email, gmdate( DATE_ATOM, time() ) );

    exit;
    }

    add_action( 'wp_ajax_omnisend_update_plugin_setting', 'omnisend_update_plugin_setting' );

    function omnisend_update_plugin_setting() {
    check_ajax_referer( 'omnisend-settings-script-nonce' );

    Omnisend_Logger::hook();
    $setting_name = isset( $_POST['setting_name'] ) ? sanitize_text_field( wp_unslash( $_POST['setting_name'] ) ) : '';
    $setting_value = isset( $_POST['setting_value'] ) ? sanitize_text_field( wp_unslash( $_POST['setting_value'] ) ) : '';
    Omnisend_Logger::info( "omnisend_update_plugin_setting - received setting_name: $setting_name, setting_value: $setting_value" );

    $setting_update_source = 'admin';

    switch ( $setting_name ) {
    case 'contact_tag':
    Omnisend_Settings::set_contact_tag( $setting_value, $setting_update_source );
    break;
    case 'contact_tag_status':
    Omnisend_Settings::set_contact_tag_status( $setting_value, $setting_update_source );
    break;
    case 'checkout_opt_in_status':
    Omnisend_Settings::set_checkout_opt_in_status( $setting_value, $setting_update_source );
    break;
    case 'checkout_opt_in_text':
    Omnisend_Settings::set_checkout_opt_in_text( $setting_value, $setting_update_source );
    break;
    case 'checkout_opt_in_preselected_status':
    Omnisend_Settings::set_checkout_opt_in_preselected_status( $setting_value, $setting_update_source );
    break;
    default:
    break;
    }

    exit;
    }

    class Omnisend_Ajax {
    /**
    * @return Omnisend_Operation_Status
    */
    public static function identify_by_email( $email, $contact_id ) {
    if ( ! Omnisend_Manager::is_setup() ) {
    return Omnisend_Operation_Status::error( 'Omnisend is not setup' );
    }

    if ( ! filter_var( $email, FILTER_VALIDATE_EMAIL ) ) {
    return Omnisend_Operation_Status::error( 'Incorrect request (email)' );
    }

    if ( Omnisend_Contact_Resolver::update_by_email( $email ) ) {
    return Omnisend_Operation_Status::success();
    }

    $api_url = OMNISEND_API_URL . '/v3/contacts';
    $curl_result = Omnisend_Helper::omnisend_api( $api_url, 'POST', self::generate_contact_payload( $email, $contact_id ) );
    if ( $curl_result['code'] < 200 || $curl_result['code'] >= 300 ) {
    Omnisend_Logger::log( 'warn', 'contacts', $api_url, 'Unable to push contact ' . $email . ' to Omnisend.' . $curl_result['response'] );

    return Omnisend_Operation_Status::error( 'Unable to create contact (api error)' );
    }
    Omnisend_Logger::log( 'info', 'contacts', $api_url, 'Contact ' . $email . ' was successfully pushed to Omnisend.' );

    $response = json_decode( $curl_result['response'], true );
    if ( empty( $response['contactID'] ) ) {
    Omnisend_Logger::log( 'warn', 'contacts', $api_url, 'Unable to push contact ' . $email . ' to Omnisend. Unexpected API response: ' . $curl_result['response'] );

    return Omnisend_Operation_Status::error( 'Unable to identify contact (api error)' );
    }

    Omnisend_Contact_Resolver::update_by_email_and_contact_id( $email, $response['contactID'] );

    return Omnisend_Operation_Status::success();
    }

    private static function generate_contact_payload( $email, $contact_id ) {
    $tags = array( 'source: woocommerce' );
    $tag = Omnisend_Settings::get_contact_tag_value();

    if ( $tag ) {
    $tags[] = $tag;
    }

    $payload = array(
    'email' => $email,
    'status' => 'nonSubscribed',
    'statusDate' => gmdate( DATE_ATOM ),
    'tags' => $tags,
    );
    if ( $contact_id ) {
    $payload['contactID'] = $contact_id;
    }
    return $payload;
    }
    }

    So i want to change the “status” when the this happened and tags as well but i don’t see any hook to do so in generate_contact_payload function.

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support supportomnisend

    (@supportomnisend)

    Thanks for posting this on the support forum — it’s always helpful to have these discussions in a shared space where others can learn and contribute as well.

    Our product team has taken a look, and from what we understand, you’re looking to change the initial subscription status — specifically, to change it from nonSubscriber to subscriber — when a user visits the site and their email is captured via the AJAX call, even without any interaction or explicit consent.

    If that’s the case, we want to flag that automatically changing the status to subscriber without user consent would not be GDPR-compliant. Consent must be given explicitly by the user, typically via an opt-in action like a checkbox or form submission.

    Could you clarify a bit more about your intended outcome? What are you trying to achieve?

    Looking forward to your clarification!

    Plugin Support supportomnisend

    (@supportomnisend)

    Additionally, from a technical perspective, there is a hook available for modifying contact data before it is sent to Omnisend: omnisend_contact_data.

    You can refer to the following article for more details and context:
    🔗 Omnisend for WooCommerce – WordPress Integration Guide

    Assuming your intended use case aligns with GDPR requirements, you might consider exploring this approach.

    We hope you’ll find this helpful. We’re still looking forward to your clarification and are happy to provide further assistance based on your specific needs.

    Thread Starter kartiksadadiya

    (@kartiksadadiya)

    Thank you for the Response, You are right subscriber without user consent would not be GDPR-compliant but let say at list there should be hook to add the tag so i know from where user is coming from. I was looking for everywhere for that user like in subscription form logs and users list but i was not able to figure out where the user is coming from. Then i realize even when user just add an email in the checkout or the amyccount page it auto sends the user to the omni send.

    I ask for “status” update coz i thought some users also coming from the subscription form but that’s not the case can i change tags at list or something in future ? So that way i won’t need to find user activity everywhere for like it it’s from checkout or page or myaccount page or let say from the form and add tag accordingly.

    Again thank you.

    Plugin Support supportomnisend

    (@supportomnisend)

    Thank you for sharing your use case and the context behind what you’re trying to achieve — that’s really helpful for us to understand your needs better.

    Based on what you’ve described, we believe the approach we mentioned earlier should work well for you. Since we provide a hook (omnisend_contact_data) that allows the contact data to be modified before it’s sent to Omnisend, you can use it to add custom tags based on where the user interaction originated (e.g., checkout, account page, forms, etc.).

    This should help you move closer to your goal in a more structured and manageable way.
    If you have any additional questions, feel free to reach out — we’ve got your back!

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.