• Resolved Grzegorz.Janoszka

    (@grzegorzjanoszka)


    Hi,

    I am a happy user of this plugin and I really appreciate it. The feature “Load tracker on all pages” was on my request and I am extremely happy it was implemented.

    Recently I have noticed however that sometimes it doesn’t work. When I use WordPress search to look for a word that _exists_ on my page, the result page contains tptn code. That is good.

    But when I look for a word that is not at all on my website, I get just a simple page with “No results found” or whatever and this page doesn’t have the tptn code.

    Would it be possible to have tracker code on every search result?

    Thank you in advance for looking into it.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Ajay

    (@ajay)

    That’s interesting. The code is loaded via wp_enqueue_scripts and does some checks to see that it loads.

    https://github.com/WebberZone/top-10/blob/master/includes/tracker.php#L31

    Are you able to do some testing to check if any of the lines between 32 to 43 cause the include_code to become false?

    Thread Starter Grzegorz.Janoszka

    (@grzegorzjanoszka)

    Ajay,
    I have commented all the lines you mentioned and nothing really changed. What I am thinking is that if there is nothing found, then maybe WP calls die and some actions are not done.

    Plugin Author Ajay

    (@ajay)

    I’m thinking the same thing but I’m not sure what the solution would be in that context as it seems to be hitting only that specific page.

    I’m wondering if other scripts that hook into wp_enqueue_scripts load on the not found page.

    One thing that comes to mind @grzegorzjanoszka is that given how you’re optimising your install, would it make sense to just write a custom function that just has these lines and remove this action.

    
    remove_action( 'wp_enqueue_scripts', 'tptn_enqueue_scripts' );
    
    Thread Starter Grzegorz.Janoszka

    (@grzegorzjanoszka)

    All other scripts load fine, the only difference is tptn. Not sure how to bite it ??

    Plugin Author Ajay

    (@ajay)

    Am thinking something like this in your functions.php. Please check closing brackets as the editor here isn’t optimised for code.

    
    remove_action( 'wp_enqueue_scripts', 'tptn_enqueue_scripts' );
    
    function tptn_enqueue_scripts_always() {
    	global $post, $ajax_tptn_tracker;
    
    			$id               = is_singular() ? absint( $post->ID ) : 0;
    			$blog_id          = get_current_blog_id();
    			$activate_counter = ! empty( $trackers['overall'] ) ? 1 : 0;     // It's 1 if we're updating the overall count.
    			$activate_counter = $activate_counter + ( ! empty( $trackers['daily'] ) ? 10 : 0 );  // It's 10 if we're updating the daily count.
    			$top_ten_debug    = absint( tptn_get_option( 'debug_mode' ) );
    
    			if ( 'query_based' === tptn_get_option( 'tracker_type' ) ) {
    				$home_url = home_url( '/' );
    			} else {
    				$home_url = admin_url( 'admin-ajax.php' );
    			}
    
    			/**
    			 * Filter the URL of the tracker.
    			 *
    			 * Other tracker types can override the URL processed by the jQuery.post request
    			 * The corresponding tracker can use the below variables or append their own to $ajax_tptn_tracker
    			 *
    			 * @since   2.0
    			 */
    			$home_url = apply_filters( 'tptn_add_counter_script_url', $home_url );
    
    			// Strip any query strings since we don't need them.
    			$home_url = strtok( $home_url, '?' );
    
    			$ajax_tptn_tracker = array(
    				'ajax_url'         => $home_url,
    				'top_ten_id'       => $id,
    				'top_ten_blog_id'  => $blog_id,
    				'activate_counter' => $activate_counter,
    				'top_ten_debug'    => $top_ten_debug,
    				'tptn_rnd'         => wp_rand( 1, time() ),
    			);
    
    			/**
    			 * Filter the localize script arguments for the Top 10 tracker.
    			 *
    			 * @since 2.4.0
    			 */
    			$ajax_tptn_tracker = apply_filters( 'tptn_tracker_script_args', $ajax_tptn_tracker );
    
    			wp_enqueue_script( 'tptn_tracker', plugins_url( 'includes/js/top-10-tracker.min.js', TOP_TEN_PLUGIN_FILE ), array( 'jquery' ), '1.0', true );
    
    			wp_localize_script( 'tptn_tracker', 'ajax_tptn_tracker', $ajax_tptn_tracker );
    
    }
    add_action( 'wp_enqueue_scripts', 'tptn_enqueue_scripts_always' );
    
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Load tracker on all pages not working’ is closed to new replies.