Problem with placing Google Analytics code

Discussion in 'JavaScript' started by Voimis, Oct 15, 2007.

  1. #1
    Hi dudes! I think this is right sub forum for this question because it´s about javascript...

    I don´t know where to place the Analytics code because my site just redirects to another one.

    Google Analytics page says that it should be placed just before </body> tag but my <head> looks like that so I think browser doesn´t load the Analytics code if it is just before </body>

    <head>
    <title>kesanekajekku -> gurun testi</title>
    <script type="text/javascript">
    <!--
    window.location = "http://www.example.com/"
    //-->
    </script>
    <meta HTTP-EQUIV="REFRESH" content="0; url=http://www.example.com">
    </head>

    So, where I should place it?

    Thanks to you guys! :)
     
    Voimis, Oct 15, 2007 IP
  2. Voimis

    Voimis Peon

    Messages:
    60
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Dudes, anyone?

    Thanks a lot!
     
    Voimis, Oct 16, 2007 IP
  3. Lordy

    Lordy Peon

    Messages:
    1,643
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    0
    #3
    just put it anywhere, it'll work anyways :p
     
    Lordy, Oct 16, 2007 IP
  4. ajsa52

    ajsa52 Well-Known Member

    Messages:
    3,426
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    160
    #4
    I don't think so.
    IMO if your javascript code executes a redirection (just like window.location = "http://www.example.com/"; ) the following code won't be executed.
    So I think you should put the analytics code before that line. That's:

    
    <head>
    <title>kesanekajekku -> gurun testi</title>
    <script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
    <script type="text/javascript">
    <!--
      _uacct = "your_account";	
      urchinTracker(); 
      window.location = "http://www.example.com/"
    //-->
    </script>
    </head>
    
    Code (markup):
     
    ajsa52, Oct 16, 2007 IP
  5. Voimis

    Voimis Peon

    Messages:
    60
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks to you, I´ll try this.

    Is it possible that someones browser doesn´t notify JavaScript redirection which I use (window.location etc..)? I mean do I need to use JavaScript redirect and also the meta-tag redirect if I want permanent redirection?

    Thanks to you!
     
    Voimis, Oct 16, 2007 IP
  6. ajsa52

    ajsa52 Well-Known Member

    Messages:
    3,426
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    160
    #6
    I thought you want that method to know how many people are going to your new site from your previous site.
    I you don't want to know that info, IMO the best way to go is through a 301 redirection set on your .htaccess file on your old site redirecting to your new site.
     
    ajsa52, Oct 16, 2007 IP
  7. Voimis

    Voimis Peon

    Messages:
    60
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I want to know everything what google analytics can provide and that´s why the analytics code in page which just redirects to another one.

    Im just thinking which would be the best script type redirection?
    freewebs.com doesn´t support PHP so I can´t use it.
    Is JavaScript the best option?
     
    Voimis, Oct 16, 2007 IP
  8. ajsa52

    ajsa52 Well-Known Member

    Messages:
    3,426
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    160
    #8
    If you want info from Google Analytics, then you NEED javascript.
    I'm not sure, but if you use the META tag redirection, probably the Analytics code won't be executed.
    So IMO your best option is the javascript redirection (window.location assignment) without the META tag redirection.
     
    ajsa52, Oct 16, 2007 IP
  9. Voimis

    Voimis Peon

    Messages:
    60
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Yes. You´re right.

    But is it possible someones browser blocks javascript and then the analytics and redirect code doesn´t work?
     
    Voimis, Oct 16, 2007 IP
  10. ajsa52

    ajsa52 Well-Known Member

    Messages:
    3,426
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    160
    #10
    Yes, you're right too.
    A small percentage of people has javascript disabled on their browsers, and will not be redirected to your new site.
    But, you can put a link on the page allowing that people to manually jump to new site.
     
    ajsa52, Oct 16, 2007 IP