Google Analytics-like code snippet?

Discussion in 'Javascript' started by Oltmans, Mar 13, 2008.

  1. Oltmans

    Oltmans Guest

    Hi,

    I'm still learning stuff and was just wondering how can I let other
    people put some function of my JavaScript on their website so that I
    can gather information from their website. Here is what I was looking
    at
    --
    <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-3358728-1");
    pageTracker._initData();
    pageTracker._trackPageview();
    </script>
    --

    This is the code that I've to put into my website so that I can use
    Google Analytics, how can I go about creating the same thing in
    JavaScript?
    As I understand above code, and I could be flat-out wrong, is that
    document.write statement in above code snippet is adding a script
    named 'ga.js' to my website and that script contains an object _gat
    that contains other functions. Is my understanding right? Moreover,
    what does the unescape thing doing in the above code? Can the above
    approach be improved?

    Please enlighten me, I will really appreciate any replies.

    Thanks and have a great day,
    Rolf
     
    Oltmans, Mar 13, 2008
    #1
    1. Advertisements

  2. [code itself snipped]
    This part of the question, I don't follow. How do you create in
    Javascript what you already have in Javascript?

    Almost, but not exactly.
    It is loading a script FROM either

    https://ssl.google-analytics.com/ga.js
    - or -
    http://www.google-analytics.com/ga.js




    and that script contains an object _gat that
    That is right.
    Google, as almost always, is your friend.
    http://www.w3schools.com/jsref/jsref_escape.asp


    Some folks would claim that removing it would be an improvement.
    Google Analytics has some known issues. Searching the archives here
    wouldn't be amiss.

    Consider your self replied ;)
     
    Jeremy J Starcher, Mar 13, 2008
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.