Skip to content

Instantly share code, notes, and snippets.

@cliffordp
Last active December 22, 2022 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cliffordp/f90a50390f51e98457512a36d02f1ef3 to your computer and use it in GitHub Desktop.
Save cliffordp/f90a50390f51e98457512a36d02f1ef3 to your computer and use it in GitHub Desktop.
NotificationX plugin: Custom link location for Google Analytics sourced notifications (default is homepage)
<?php
/**
* NotificationX plugin: Custom link location for Google Analytics sourced notifications (default is homepage).
*
* @link https://gist.github.com/cliffordp/f90a50390f51e98457512a36d02f1ef3 This snippet.
*
* @see \NotificationX\FrontEnd\FrontEnd::link_url
*/
add_filter( 'nx_notification_link_google', function( $link, $post, $entry ){
// !!! CHANGE THIS TO YOUR "CONTACT US" PAGE ID !!!
$target_page_id = 88;
/*
error_log( 'LINK' );
error_log( $link );
error_log( 'POST' );
error_log( print_r( $post, true ) );
error_log( 'ENTRY' );
error_log( print_r( $entry, true ) );
*/
$new_link = add_query_arg( [
'utm_id' => $post['id'], // The Notification's ID.
// Not possible as NotificationX's REST request does not include it.
//'utm_content' => 'from_id-' . get_queried_object_id(),
'utm_source' => 'fomo',
'utm_medium' => 'popup',
'utm_campaign' => 'notificationx',
], get_permalink( $target_page_id ) );
return esc_url_raw( $new_link );
}, 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment