Support » Fixing WordPress » Included php file doesn't work in template but works fine in external php file

  • Hi fellow WordPressers

    I am using a script to track visits from bots/spiders/crawlers in Google Analytics but I am only partly successful.

    The script is located in an external php file called ga.php and I include it in the header of my template and in my spiderTrap.php file. All bots that crawl spiderTrap.php are blocked from my entire website using their ip-adresses.

    The bot visits to the spiderTrap.php registers fine in Google Analytics but nothing registers for the WordPress controlled part of my website.

    The way I include ga.php in the spiderTrap.php and in the template header is by doing this:

    /**********GA For Search Bots**************/
    
    //Configuration
    $GA_SB_ACCOUNT = "MO-XXXXXXXX-X"; //Replace with GA profile id. make sure to replace UA with MO
    $GA_SB_PATH = $_SERVER['DOCUMENT_ROOT']."/gaforsearchbots/ga.php"; //location of the GA for Search Bots script
    
    $status = "";
    
    if (file_exists($GA_SB_PATH)){
    	$status = "True";
    	include($GA_SB_PATH);
    }
    else {$status = "False";}
    
    /**********GA For Search Bots**************/

    The only way bots can crawl spiderTrap.php is by starting on the WordPress part of my website which then links to the spiderTrap.php. This means that the tracking of those bots should already begin on my WordPress site.

    Does anyone here have a suggestion as to why the tracking works when included in an external file (spiderTrap.php) but not when it is included in the header of my template?

  • The topic ‘Included php file doesn't work in template but works fine in external php file’ is closed to new replies.