1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Inserting Google Analytics code into PHP page

Discussion in 'PHP' started by pkallberg21, Aug 3, 2007.

  1. #1
    My index file for my website is pure PHP, how would I go about inserting the analytics code into it? Will it track all websites throughout my website that way?

    Thanks.
     
    pkallberg21, Aug 3, 2007 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    Try something like this. You can echo or print it out on your page. I recommend doing it at the bottom of the footer so that you don't slow down your website's display time.

    
    
    echo '
    <script src="https://ssl.google-analytics.com/urchin.js" type="text/javascript">
    </script>
    <script type="text/javascript">
    _uacct = "YOURINFOHERE";
    urchinTracker();
    </script>';
    
    
    PHP:
     
    jestep, Aug 3, 2007 IP
    exodus likes this.
  3. Jezek

    Jezek Peon

    Messages:
    34
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Why don't you just end the php tag before you insert the js code? Since you wouldn't need any more php since it should be at the bottom of the page.
     
    Jezek, Aug 3, 2007 IP
  4. exodus

    exodus Well-Known Member

    Messages:
    1,900
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    165
    #4
    Find where the </body></html> tags are located and just above that put the code that jestep meationed.

    echo '<script src="https://ssl.google-analytics.com/urchin.js" type="text/javascript"></script><script type="text/javascript">_uacct = "YOURINFOHERE";urchinTracker();</script>';
    PHP:
     
    exodus, Aug 3, 2007 IP
  5. pkallberg21

    pkallberg21 Peon

    Messages:
    295
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Yeah that was my first thought, but there are no html and body tags. I tried creating them in different locations but it isn't working.
     
    pkallberg21, Aug 3, 2007 IP
  6. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #6
    Surely you can just put it at the very bottom. Outside of the ?> tag.
     
    Danltn, Aug 4, 2007 IP
  7. pkallberg21

    pkallberg21 Peon

    Messages:
    295
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Ok, I have tried that, but I am not getting any views/visits on my Analytics page. Here is the code for the main index.php page:

    <?php
    error_reporting(E_ALL & ~E_NOTICE);
    define('NO_REGISTER_GLOBALS', 1);
    define('THIS_SCRIPT', 'adv_index');
    define('VBA_PORTAL', true);
    define('VBA_SCRIPT', 'CMPS');
    
    
    $forumpath = '/home/www/website/forum';
    
    
    if ($forumpath)
    {
    	if (!is_dir($forumpath))
    	{
    		echo 'Invalid forum path specified! Please edit this file and be sure to include the correct path for your $forumpath variable.';
    		exit;
    	}
    
    	chdir($forumpath);
    }
    
    $phrasegroups = array();
    $globaltemplates = array();
    $actiontemplates = array();
    $specialtemplates = array();
    
    require_once('./includes/vba_cmps_include_template.php');
    require_once('./global.php');
    
    print_portal_output($home);
    ?>
    
    
    PHP:
    Where would you put the analytics code?
    Thanks.
     
    pkallberg21, Aug 5, 2007 IP
  8. pfek

    pfek Member

    Messages:
    98
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    45
    #8
    Looks like it might me in the './includes/vba_cmps_include_template.php' file. Seems like your file uses a template managing. The </body> tag should be in that file.
     
    pfek, Aug 5, 2007 IP
  9. pkallberg21

    pkallberg21 Peon

    Messages:
    295
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Nope, the vba_cmps_include_template.php file is also just full of php :confused:
     
    pkallberg21, Aug 5, 2007 IP
  10. pkallberg21

    pkallberg21 Peon

    Messages:
    295
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Anyone who knows where I should put the analytics code?

    Thanks.
     
    pkallberg21, Aug 6, 2007 IP
  11. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #11
    Can you post the code of the vba_cmps_include_template.php. i would look for further includes on that page or functions that look like they call specific parts of the actual html.

    Is this a specific CMS that you are using? That might help us figure out where the html for the template it at.
     
    jestep, Aug 6, 2007 IP
  12. pkallberg21

    pkallberg21 Peon

    Messages:
    295
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Ok here it is:

    <?php
    error_reporting(E_ALL & ~E_NOTICE);
    
    $phrasegroups = array_merge($phrasegroups,
    	array(
    		'calendar',
    		'adv_portal',
    		'postbit'
    	)
    );
    
    $specialtemplates = array_merge($specialtemplates,
    	array(
    		'adv_modules',
    		'adv_portal_cale',
    		'adv_portal_home',
    		'adv_portal_opts',
    		'adv_portal_page',
    		'adv_portal_tpst',
    		'attachmentcache',
    		'bbcodecache',
    		'birthdaycache',
    		'eventcache',
    		'iconcache',
    		'maxloggedin',
    		'rankphp',
    		'smiliecache',
    		'userstats'
    	)
    );
    
    $globaltemplates = array_merge($globaltemplates,
    	array(
    		'adv_portal',
    		'adv_portal_footer',
    		'adv_portal_nodisplay'
    	)
    );
    
    ?>
    PHP:
    This is vBAdvanced CMPS, a plugin for vBulletin. Hope you can help :)
     
    pkallberg21, Aug 6, 2007 IP
  13. gwkg

    gwkg Peon

    Messages:
    143
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #13
    search all the code for </body> it should go right before the closing body tag.

    adv_portal_footer or adv_portal_nodisplay would be my guess, but search all the code if its not there.
     
    gwkg, Aug 6, 2007 IP
  14. pkallberg21

    pkallberg21 Peon

    Messages:
    295
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #14
    I found a solution to this problem finally :) I just had to enter the code into the footer template of vBulletin, because this way it will track all pages and still be on the vBAdvanced homepage.

    Thanks for everyones help :) Very appreciated.
     
    pkallberg21, Aug 6, 2007 IP