Google Analytics-like code snippet?

O

Oltmans

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
 
J

Jeremy J Starcher

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

[code itself snipped]
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?

This part of the question, I don't follow. How do you create in
Javascript what you already have 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

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
contains other functions. Is my understanding right?

That is right.
Moreover, what does the unescape thing doing in the above code?

Google, as almost always, is your friend.
http://www.w3schools.com/jsref/jsref_escape.asp


Can the above approach be improved?

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.

Please enlighten me, I will really appreciate any replies.

Consider your self replied ;)
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top