Jump to content

  • Log In with Google      Sign In   
  • Create Account

whats this? javscript/ga


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • This topic is locked This topic is locked
28 replies to this topic

#1 fir   Members   -  Reputation: -456

Like
0Likes
Like

Posted 08 June 2014 - 09:03 AM

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
 


Sponsor:

#2 Andy Gainey   Members   -  Reputation: 2103

Like
5Likes
Like

Posted 08 June 2014 - 09:23 AM

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

#3 rip-off   Moderators   -  Reputation: 8727

Like
5Likes
Like

Posted 08 June 2014 - 09:29 AM

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.

#4 fir   Members   -  Reputation: -456

Like
0Likes
Like

Posted 08 June 2014 - 09:38 AM

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?



#5 rip-off   Moderators   -  Reputation: 8727

Like
4Likes
Like

Posted 08 June 2014 - 10:15 AM

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.

#6 fir   Members   -  Reputation: -456

Like
-1Likes
Like

Posted 08 June 2014 - 11:10 AM

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)


Edited by fir, 08 June 2014 - 11:14 AM.


#7 rip-off   Moderators   -  Reputation: 8727

Like
7Likes
Like

Posted 08 June 2014 - 11:34 AM

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

#8 Madhed   Crossbones+   -  Reputation: 3134

Like
4Likes
Like

Posted 08 June 2014 - 12:46 PM

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

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



#9 fir   Members   -  Reputation: -456

Like
-13Likes
Like

Posted 08 June 2014 - 01:14 PM

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 )  ]


Edited by fir, 09 June 2014 - 04:28 AM.


#10 fir   Members   -  Reputation: -456

Like
-4Likes
Like

Posted 08 June 2014 - 01:30 PM

Google search: HTML script tags order of execution

Google search: navigator.userAgent

 

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?



#11 rip-off   Moderators   -  Reputation: 8727

Like
10Likes
Like

Posted 08 June 2014 - 01:43 PM

trying to research it myself is not my methodology today - sometimes it is more effective to talk with somebody ho knows

Well, typically you have to pay money if you want someone to walk you through everything. If you want free help from the Internet, you'll run out of volunteers quickly unless you demonstrate you've made some attempt to do your own research.

that - and im looking for such place here [there are some reasons for that, (if you just call me lazy you may miss some point, though its to long to explain ) ]

There is lots of brilliant information that someone already went to great lengths to create just waiting for you to find it. I've no problem if you cannot find such information after making an honest search (provided you mention the kind of searches that weren't fruitful), or if you cannot understand the information when you do find it (provided it is clear which parts you're having trouble with).

However, being unwilling to do some basic research first is lazy. It wastes not only the time of the people who've already written about these subjects, but also people on these forums (or elsewhere) reproducing such information.

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?

What have you tried?

#12 fir   Members   -  Reputation: -456

Like
-11Likes
Like

Posted 08 June 2014 - 02:22 PM

 

trying to research it myself is not my methodology today - sometimes it is more effective to talk with somebody ho knows

Well, typically you have to pay money if you want someone to walk you through everything. If you want free help from the Internet, you'll run out of volunteers quickly unless you demonstrate you've made some attempt to do your own research.

that - and im looking for such place here [there are some reasons for that, (if you just call me lazy you may miss some point, though its to long to explain ) ]

There is lots of brilliant information that someone already went to great lengths to create just waiting for you to find it. I've no problem if you cannot find such information after making an honest search (provided you mention the kind of searches that weren't fruitful), or if you cannot understand the information when you do find it (provided it is clear which parts you're having trouble with).

However, being unwilling to do some basic research first is lazy. It wastes not only the time of the people who've already written about these subjects, but also people on these forums (or elsewhere) reproducing such information.

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?

What have you tried?

 

 

i disagree imo you see it wrong,

 

1. First youre too pesymistic as to this volounteers I have made some talks when people just talked with me and didnt want me to pay me to them (that would be a bit awfull), i also provided help with them - (providing help is not just waste of time if you think so at leas not for me  it helped me to clarify the things too, )

 

2. i know tahat there are tons of materials waiting for me, I can learn it quite easily though It is a last resort for me becouse I just prefer a talk way and cannos spend much time this time on it

 

maybe someone should write a paper "why not to do private research first" (but talk to fellows, this is quite obvious - IMO this attitude to send asker to a google is not so much logically right  as this is often presented - so i just disagree wuth this argumentation 


Edited by fir, 08 June 2014 - 02:25 PM.


#13 rip-off   Moderators   -  Reputation: 8727

Like
8Likes
Like

Posted 08 June 2014 - 02:32 PM

I'll take that as a "no, I haven't tried anything".

As someone who has put much time into volunteering to help many people on these forums and elsewhere, I believe my opinion is more informed than yours on this matter. However, this is derailing the thread, so I'll speak no more about it.

#14 fir   Members   -  Reputation: -456

Like
-3Likes
Like

Posted 08 June 2014 - 02:34 PM

yet as to my questions: in thic code link i provided there is many sentences like this. (many thises).

 

like here

 

 

  function Controls() {
        this.codes  = { 37: 'left', 39: 'right', 38: 'forward', 40: 'backward' };
        this.states = { 'left': false, 'right': false, 'forward': false, 'backward': false };

      ....

}

 

and many other thises

 

 

What is this this adreessee/receiver? is this canvas or are they refering to different objects here, what it is?

 

what is 

 

Controls.prototype.onTouch = function(e) {

 

does this mean tat this function is a method of some object called controls? and this in this method refers to controlls?

 

that would be helpfull, tnx



#15 fir   Members   -  Reputation: -456

Like
0Likes
Like

Posted 08 June 2014 - 02:38 PM

I'll take that as a "no, I haven't tried anything".

As someone who has put much time into volunteering to help many people on these forums and elsewhere, I believe my opinion is more informed than yours on this matter. However, this is derailing the thread, so I'll speak no more about it.

 

not a problem :)



#16 Madhed   Crossbones+   -  Reputation: 3134

Like
2Likes
Like

Posted 08 June 2014 - 03:04 PM

fir, you should probably first learn the basics of javascript before diving into canvas stuff etc. As a seasoned js coder I can assure you that you will have many more WTF moments in the future.

 

Most of the stuff you have asked here will be covered in any javascript tutorial online.

 

* Quirks of the *this* pointer

* event handlers

* regular expressions

 

etc etc.



#17 fir   Members   -  Reputation: -456

Like
0Likes
Like

Posted 08 June 2014 - 03:40 PM

fir, you should probably first learn the basics of javascript before diving into canvas stuff etc. As a seasoned js coder I can assure you that you will have many more WTF moments in the future.

 

Most of the stuff you have asked here will be covered in any javascript tutorial online.

 

* Quirks of the *this* pointer

* event handlers

* regular expressions

 

etc etc.

 

Im reading it but it goes slowly, answers could speed up the thing a bit 

 

ps. but if you want you can give me some links to such tutorials i will sweep them then


Edited by fir, 08 June 2014 - 04:33 PM.


#18 fir   Members   -  Reputation: -456

Like
0Likes
Like

Posted 09 June 2014 - 04:19 AM

so, anyone? 



#19 phantom   Moderators   -  Reputation: 7565

Like
3Likes
Like

Posted 09 June 2014 - 04:21 AM

Do not bump your posts so soon after your last one, wait at least 24h between posts to give people a chance to reply.

#20 fir   Members   -  Reputation: -456

Like
0Likes
Like

Posted 09 June 2014 - 04:25 AM

Do not bump your posts so soon after your last one, wait at least 24h between posts to give people a chance to reply.

alright, i wanted to say that this questions are still open , If some provide answers i can give maybe two or three yet more on this topic






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS