views:

63

answers:

2

I have an application which runs on mobile devices such as android, and I have some third party traffic tracking js code to track the usage of my application. So everytime a user opens up my application the js code sends a ping to the 3rd party tracking server. However I'm not sure if there's an easy way to embed the js code directly into my application that's not browser based and couldn't interpret js code. So I may have to execute the js code on the server side. The 3rd party code is like this :

<script type="text/javascript" src="http://www.3rdparty.com/tracking.lib.js"&gt;&lt;/script&gt;
<script type="text/javascript">
   var instance = new Tracking();
   instance.run();
</script>

What's the easiest way to run this code on server side?

Thanks in advance.

A: 

I'm not sure if it is really possible.

If it is a Java-Server you can use the BeanScripting Framework, but:

If the Javascript code does some calculation like Screen-Size, Browser etc. You won't get that information.

You can't get the IP nore the HTTP-Client (Which Browser etc.).

I Don't know the JavaScript code, so I may be wrong.

In fact, the Javascript code will call your Server to store the information. You can reverse engeneer the infromation sent, by using a Network-Sniffer.

ckuetbach
+3  A: 

There are several solutions for running server side javascript (Node.JS, or something based on Rhino), but that code is probably dependent on functionality that only exists in a browser.

EDIT

I answered the question, but I didn't really address the problem. Even if the code will execute run on the server, it won't work as intended. You really need to come up with a better solution for tracking usage of a non web based application.

The question you should have asked is: How can I track usage of an android application?

If you are already running a server, they you could write a simple web service that logs usage, you just need to open a HTTP connection from within your app.

I would be surprised if there aren't existing solutions, but I'm not an Android guy, so I wouldn't know.

I would suggest deleting this question and replacing it with one targeting what you are actually trying to accomplish.

mikerobi
@mikerobi: Thanks. But could you elaborate how to do that in node.js?
Shawn
@Shawn, updated my answer to be more helpful.
mikerobi