whats this? javscript/ga

Started by
27 comments, last by jpetrie 9 years, 10 months ago

when trying to learn a bit javascript canvas game tehnology

on the bottom of the code i found something like

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-50885475-1', 'playfuljs.com');
ga('send', 'pageview');
</script>
</body>
</html>
would someone able to explain me ehat it is, if as im writing a canvas game should paste it myself
or what, and a bit what this script is doin (how it is workin line by line)
?
tnx
Advertisement

That's used for Google Analytics, which allows the operator of a website to collect generic information about people visiting the site. (How many visits, where they're coming from, what device & operating system they're using, which links they follow, et cetera.)

It will be unique for each website. Any sample code that includes that is sloppy sample code, to be honest. It will only work on the original person's website, and will be wasted effort on anyone else's page. You can safely delete the <script> tag and everything within it, as it has nothing to do with the actual sample.

"We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas only, and not for things themselves." - John Locke
This is nothing to do with a game, it is tracking code that fetches Google's analytics script and inserts it into the page. Doing so allows the webmaster to understand how their site is doing, which pages are popular and how people navigate the side.

I won't go through it line by line, but essentially it is creating a new <script> tag and pointing it at Google's script. This way Google can update their script and everyone sees the new version right away, rather than hosting a potentially out of date script. It is written in the form of an Immediately Invoked Function Expression, and is quite terse: using very short variable names and minimal whitespace.

If you had your own website and wanted to do the same, you might insert a similar script - I believe it is boilerplate that you copy from your Google Analytics account, if you create one.

allright that was very helpfull, Could you say meybe a bit more, : if this is some script that collects some information ehen he is storing it, and how me as a webpage owner can use this information (just for curiosity), also would it slow a canvas game or its page or not at all?

Google is storing the data. The webmaster logs into Google Analytics and can see all sorts of information about the number of visitors and what they do on the site.

It won't slow an active game, but there would be a minor impact on the time taken to fetch the page and it's resources.

allright,

could I maybe ask here few of some simple javascript related questions?

Im trying to understand some thing if some could answer some question it would be helpfull

Im trying to quickly analyze such code

https://github.com/hunterloftis/playfuljs/blob/master/content/demos/raycaster.html

but my knowledge is little (an i had not to much time to learn it,

but would like to understand it as far much as possible)

one is -

if si got some page with two scripts like here <script> </script> <script> </script>, which one is running first? is one firing the another or what? could someone explain? (if so tnx, )

the second would be

var MOBILE = /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent)

- whats this? its looking very strange (as for m c ground man)

From your responses, it is unclear if you're even trying to research these topics at all.

if si got some page with two scripts like here <script> </script> <script> </script>, which one is running first? is one firing the another or what? could someone explain? (if so tnx, )

Google search: HTML script tags order of execution

the second would be

var MOBILE = /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent)

- whats this? its looking very strange (as for m c ground man)

Google search: navigator.userAgent

/Android|webOS|iPhone|iPad|iPod|BlackBerry/i

Is a regular expression. Javascript has a special syntax to create them on the fly.

From your responses, it is unclear if you're even trying to research these topics at all.

trying to research it myself is not my methodology today - sometimes it is more effective to talk with somebody who knows that - and im looking for such place here [there are some reasons for that, (if you just call me lazy you may totally miss some point, really, though its probably to long to explain this thing ) ]

that was a bit helpful but as i do not know html/javascript those link do not say me much - navigator i dint understood at all, as to script tags, they say that they are executed sequentially what if there is a game in the first which has a loop so it do not ends, then the second is never called?

This topic is closed to new replies.

Advertisement