Google Analytics - PHP - Tracking trouble

Discussion in 'PHP' started by samvincent08, Jan 2, 2010.

  1. #1
    My client is running a website that runs on a free ecommerce script. The scripts support says to include the google analytics code in the themes > core file i.e., there is a theme/core.php file.

    In that before close HTML, he is supposed to insert google code.

    
    # Add WYSIWYG (if found) to output
    IF ($_CCFG['WYSIWYG_CLOSE']) {$_out .= $_CCFG['WYSIWYG_CLOSE'];}
    
    # HERE IS WHERE THE CODE IS TO BE 
        
    $_out .= '<script type="text/javascript">
    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
    document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
    </script>
    <script type="text/javascript">
    try {
    var pageTracker = _gat._getTracker("UA-1234567-89");
    pageTracker._trackPageview();
    } catch(err) {}</script>'
       
    # Close html
    $_out .= '</body>'.$_nl;
    $_out .= '</html>'.$_nl;
    PHP:
    But all we get is a blank page. Another person said this
    Any idea ?!?!?!?!?!?
     
    samvincent08, Jan 2, 2010 IP
  2. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #2
    you should learn php first

    1.when u add a value to a php variable you shd escape string

    2. you did not ended the statement by semicolon

    3. write a simple program in php that echo google analytics data on screen using variable

    thanks

    I hope it will help you

    Regards

    Alex


    Regards

    Alex
     
    kmap, Jan 2, 2010 IP
  3. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #3
    Try this:

    <?php
    
    // Add WYSIWYG (if found) to output
    IF ($_CCFG['WYSIWYG_CLOSE']) {
    $_out .= $_CCFG['WYSIWYG_CLOSE'];
    }
    
    // HERE IS WHERE THE CODE IS TO BE
       
    $_out .= <<<GOOGLE
    <script type="text/javascript">
    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
    document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
    </script>
    <script type="text/javascript">
    try {
    var pageTracker = _gat._getTracker("UA-1234567-89");
    pageTracker._trackPageview();
    } catch(err) {}</script>
    GOOGLE;
       
    // Close html
    $_out .= '</body>'.$_nl;
    $_out .= '</html>'.$_nl;
    
    
    ?>
    PHP:
     
    danx10, Jan 2, 2010 IP
  4. samvincent08

    samvincent08 Guest

    Messages:
    231
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hey thanks a lot. That seems to be working. Page is loading fine and GA says tracker installed. Just waiting to see reports in GA :) Thanks again.

     
    samvincent08, Jan 3, 2010 IP