WordPress.org

Ready to get started?Download WordPress

Forums

Included php file doesn't work in template but works fine in external php file (1 post)

  1. Esben Rasmussen
    Member
    Posted 3 years ago #

    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?

Topic Closed

This topic has been closed to new replies.

About this Topic

  • RSS feed for this topic
  • Started 3 years ago by Esben Rasmussen
  • This topic is not resolved
  • WordPress version: 3.2.1