• Resolved nolesnyc

    (@nolesnyc)


    I would like to trigger a hook when a specific page is visited. I would just like the payload to included the full URL (including parameters).

    Is this the proper plugin for this function?

    • This topic was modified 4 years, 6 months ago by nolesnyc.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Ironikus

    (@ironikus)

    Hey @nolesnyc – Thank you a lot for your message, as well as for your interest in our plugin. ??
    It surely can help with it, even tho the feature you requested is not included within the default functionality of the plugin.

    To make it work, here’s what you need to do:

    1. Activate the Send Data On Custom Action webhook trigger
    2. Add a new webhook URL where you want to send the data to and as a webhook name, please include send_on_pageview
    3. Please paste the following code into your functions.php file:

    add_shortcode( 'WPWH_FIRE_ON_SITE_VIEW', 'wpwh_fire_webhook_on_site_view' );
    function wpwh_fire_webhook_on_site_view( $attr = array(), $content = '' ){
    
    	//Prevent the hook from being fired in the backend 
    	if( is_admin() ){
    		return '';
    	}
    
    	$custom_data = array(
    		'page_url' => (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"
    
    	);
    	$webhook_names = array(
    		'send_on_pageview'
    	);
    	$http_args = array(
    		'blocking' => false //Set this to true to receive the response
    	);
    	
    	$response = apply_filters( 'wp_webhooks_send_to_webhook_filter', array(), $custom_data, $webhook_names, $http_args );
    
    	return '';
    }

    4. Once that’s done, simply paste the following shortcode on the site you would like to send the webhook from: [WPWH_FIRE_ON_SITE_VIEW]

    Wherever you post this shortcode, the webhook trigger will be fired. The code above includes some functionality that adds only the URL to the payload of the receiving service. The URL value hast the argument(key) page_url.

    In case you have any further questions, feel free to let me know at any time. ??

    Thread Starter nolesnyc

    (@nolesnyc)

    Thank you so much for your quick and extremely helpful response. It’s refreshing when you find a plugin with good dev support. I’ll be purchasing the pro version now even though I don’t really need it. Thanks again

    Plugin Contributor Ironikus

    (@ironikus)

    Hey @nolesnyc – Thank you a lot for your answer, as well as for supporting our plugin – We’re glad you like it and in case you have any further questions, feel free to ask at any time! ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Trigger Hook when a specific page is visited’ is closed to new replies.