7

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"></script>
<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.

1
  • 1
    I think you should investigate what that code is doing before deciding whether running on the server makes any sense. For example: most tracking tools like that rely on a cookie, which needs to be a unique value per client.
    – Pointy
    Oct 29, 2010 at 14:01

3 Answers 3

8

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.

0
1

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 nor 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.

0

'So I may have to execute the js code on the server side. ' no need it to run on a nclient side browser, or browser lke component in your native app - "Web view" or ask them for a REST API, get info of handset from native code and call the API (web service all over http in most cases)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.