Google Analytics-like code snippet?

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

  1. Oltmans

    Oltmans Guest


    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
    <script type="text/javascript">
    var gaJsHost = (("https:" == document.location.protocol) ? "https://
    ssl." : "http://www.");
    document.write(unescape("%3Cscript src='" + gaJsHost + "google-' type='text/javascript'%3E%3C/script%3E"));

    <script type="text/javascript">
    var pageTracker = _gat._getTracker("UA-3358728-1");

    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
    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,
    Oltmans, Mar 13, 2008
    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
    - or -

    and that script contains an object _gat that
    That is right.
    Google, as almost always, is your friend.

    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
    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.