Use NuTracking Library with Unity WebPlayer

Posted by on Aug 25, 2011

Unity 3′s WebPlayer use a strict security model. It blocks the network connection to third-party websites, unless a cross-domain policy file is deployed. Unfortunately, it also blocks the HTTP requests sent from NuTracking Library.

Check the Unity documentation for more details.

Since NuTracking Library 0.2.0, we used a walk around solution to solve the problem. Instead of sending HTTP requests from Unity application, we use ExternalCall to ask the web browser call the original ga.js and access the service of Google Analytics directly.

To use NuTracking Library with WebPlayer, you need to include the following code in <head> section.

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "' type='text/javascript'%3E%3C/script%3E"));
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-xxxxxx-x");
} catch(err) {}</script>

It might be put just before the line: ¬†<script type=”text/javascript” src=”UnityObject.js”></script>