Code:
Problem description:
I'm curious about how I would get Google Analytics to output pageviews from within a BYOND browser control. The obvious choice of action would be to just have an invisible browser load up the GAQ javascript, but that puts a really high cpu load on the client for some reason, and ultimately does not do anything.
Sep 10 2013, 3:58 pm
|
|
Do it as you'd do it on any other browser. What exactly is the problem?
|
I don't understand why you need to track users in a game using web based analytics... what exactly are you trying to do? gather information about the user? IP location browser type? (will be IE each time)..
|
In response to Xerif
|
|
Xerif wrote:
Do it as you'd do it on any other browser. What exactly is the problem? Doohl wrote: ... but that puts a really high cpu load on the client for some reason, and ultimately does not do anything A.T.H.K wrote: I don't understand why you need to track users in a game using web based analytics... what exactly are you trying to do? gather information about the user? IP location browser type? (will be IE each time).. Well, I had an idea for tracking player activity and live statistics via Google Analytics, without having to write all the information-acquiring myself. Plus it would serve as a really easy way to have all the information readily available on the Google Analytics website itself. Why I would want this isn't really relevant, it's how I would go about doing it. I've thought about having a remote php script being executed with the Google Analytics PHP api but that seems a bit outdated and undermaintained than the core JS API itself. |
The only way to do it is in a browser so you're out of luck, you should only need to call it once to grab sufficient data.
Not sure if you can include JS in a skin? I doubt it though. |
Can't you just use a hidden browser (layered under the map element so nobody will ever see it) embedded in your application pointed to a website you would host off-site?
The JS API would be able to be used on your site that you link the player to on connection to your game. |
In response to A.T.H.K
|
|
A.T.H.K wrote:
The only way to do it is in a browser so you're out of luck, you should only need to call it once to grab sufficient data. You can. You can even invoke javascript functions from DM using the following feature: Output: (Excerpt from the reference) The browser control in an interface can be used to execute javascript via the output() command. The format is: target << output("[params]","[control]:[scriptname]") where "[params]" is a url-encoded list of string arguments to the javascript function, as formatted by list2params(). Example: mob/Login() This allows for the creation of more dynamic interfaces, since javascript provides access to many client-side operations and flicker-free updates. |
In response to Ter13
|
|
Ter13 wrote:
Can't you just use a hidden browser (layered under the map element so nobody will ever see it) embedded in your application pointed to a website you would host off-site? This seems to work, but only if I have the browser visible, and only if I can type in the actual url. Am I missing some functionality to use browse() for urls instead of raw html text? I've tried iframes, but those don't seem to trigger the analytics code. |
Use the link() function to have the player view an external url.
Otherwise, you can use a javascript hack to redirect the browser to an external url after browsing them a webpage containing the redirect. Secondly, a browser has to be visible to browse to a location. You can, however, hide it under another element to have it show the page, which is why I suggest hiding it under the map element. |
In other words, when he said visible, he meant HIDING it below other elements using layers, not setting visible to false. Which should be obvious. The browser starts out on another page. Then you link it the url you're looking the player to trigger. Besides the fact that the player would probably notice their mouse cursor changing to the hourglass, it'd be pretty much an invisible process. It's through this same method you can play any music you'd like, granted the player has a connection to the internet.
Basically, as long as the browser is set to default, and you use link, client << link("http://www.google.com") It'll show up on that browser. In other words, the browser you should have hidden behind your other elements. Which will trigger analytics. Which will give you the results you want. This isn't perfect and result in a small flicker (you'll see the mouse flicker to hourglass and back) but it's hardly noticeable, and it'll do you fine. Getting rid of the flicker is far more trouble than its worth. |
http://stackoverflow.com/questions/4744751/ javascript-redirect
In case you need help with a javascript redirect. It's not technically a hack, and I'm not sure it'll work in BYOND if not, just embed a link in a page, and manually invoke a click command. I know this works, as that's how I callback topic data from JS-enabled webpages I browse to the client. |
Really all I did was just something simple like
var/t = {"<script>window.location = "url.com"</script>"} But yeah, this has been really helpful, thanks everyone! |
That's pretty much how I do it, just made it into a proc call.
client/proc/LinkBrowse(link,browser_element) |
I used to just use this: http://www.byond.com/forum/?post=195095
The Snippets Database had some pretty nice things. It used to be organized into a dozen subcategories, but now it's all mixed into one ugly section. |