Email notification when registred user clicks a link/visits page

To achieve your goal of tracking when a signed-up user clicks on a link/button or visits a specific page on your WordPress site, and then sending an email notification with their details, you can follow these steps. Since you are using the User Registration plugin, we’ll make sure to utilize its features where relevant.

Step 1: Tracking User Activity
To track user clicks or page visits, you can use a custom JavaScript. This script will detect when a user interacts with a specific element (like a button or link) or visits a particular page.

Identify the Element or Page: Determine the ID or class of the button/link or the specific page you want to track.

JavaScript Tracking: Add a JavaScript snippet to your site that listens for clicks on the identified element or for page visits. You can add this script in your includes/js/script.js file.

<script>
jQuery(document).ready(function($) {
    $('#yourElementId').click(function() {
        var userData = {
            'action': 'track_user_activity',
            'user_id': wpb_user_info.user_id, // assuming user ID is available
            'username': wpb_user_info.username // assuming username is available
        };

        $.post(wpb_ajax_url, userData, function(response) {
            // Handle response if needed
        });
    });
});
</script>

Replace #yourElementId with the ID or class of your element. wpb_user_info and wpb_ajax_url are placeholders and need to be replaced with actual data and AJAX URL.

Step 2: AJAX Handler in WordPress
You’ll need to create an AJAX handler in WordPress that receives the data from your JavaScript and then sends the email.

Enqueue the Script and Localize Script: Use wpb_enqueue_scripts_plugin_name to enqueue your script and pass data like AJAX URL and user info to JavaScript.

function wpb_enqueue_scripts_plugin_name() {
    wp_enqueue_script('wpb_custom_script', get_template_directory_uri() . '/includes/js/script.js', array('jquery'), mt_rand(00000, 9999999), true);

    wp_localize_script('wpb_custom_script', 'wpb_user_info', array(
        'user_id' => get_current_user_id(),
        'username' => wp_get_current_user()->user_login,
        'wpb_ajax_url' => admin_url('admin-ajax.php')
    ));
}
add_action('wp_enqueue_scripts', 'wpb_enqueue_scripts_plugin_name');

AJAX Callback Function: Create a function in your plugin’s main file to handle the AJAX request.

function wpb_track_user_activity() {
    $user_id = $_POST['user_id'];
    $username = $_POST['username'];

    // Perform your checks here

    // Send email notification
    $to = '[email protected]';
    $subject="User Activity Notification";
    $message = "Username: $username\nUser ID: $user_id";
    wp_mail($to, $subject, $message);

    echo 'Email sent';
    wp_die();
}
add_action('wp_ajax_track_user_activity', 'wpb_track_user_activity');
add_action('wp_ajax_nopriv_track_user_activity', 'wpb_track_user_activity');

This setup allows you to track user activity on specific elements or pages and receive email notifications with user details, aiding in managing registrations for events on your WordPress site.

deneme bonusudeneme bonusu veren sitelerpulibet girişOnwin Güncel Giriştürkçe altyazılı pornocanlı bahis casino