The New Google Analytics

Discussion in 'JavaScript' started by eniva, Jul 7, 2008.

  1. #1
    Ok as most of you new google analytics now has the javascript function which is supposed to be better than the legacy.

    Here is my question.

    Can I call this externally with only one call?

    For Example?

    <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">
    var pageTracker = _gat._getTracker("UA-xxxxxxx-xx");
    pageTracker._initData();
    pageTracker._trackPageview();
    </script>

    That is what google analytics gives you .. now i want to call this externally such as putting that in its own file.js and calling it with the code <script type="text/javascript" src="file.js"></script>

    Now I know when i make the file.js I need to remove the <script type="text/javascript"> and </script> part ..

    BUT

    When I leave both the

    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"));

    var pageTracker = _gat._getTracker("UA-xxxxxxx-xx");
    pageTracker._initData();
    pageTracker._trackPageview();

    in the FILE.js it does not work .. I have to put them in separate .js files and call them as

    <script type="text/javascript" src="file.js"></script>
    <script type="text/javascript" src="file1.js"></script>


    Does anyone know why this is or how to fix this to only call it from one file?

    Please let me know, thanks in advance!
     
    eniva, Jul 7, 2008 IP
  2. eniva

    eniva Active Member

    Messages:
    305
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    58
    #2
    can anyone help me out here?
     
    eniva, Jul 8, 2008 IP