Search Unity

Call Javascript from different web page

Discussion in 'Scripting' started by paolo_lionhg, Dec 29, 2013.

  1. paolo_lionhg

    paolo_lionhg

    Joined:
    Sep 5, 2013
    Posts:
    17
    I'm trying to add analytics to my web game. I want to use flurry because my games in the mobile platform are also using this.

    Anyway....assuming that I would submit my .unity3d file to portals, I have no access to their web page. This means, I can't use Application.ExternalCall. I plan to call a webpage from my server so that all the games in different portals would just call that and execute the flurry functions.

    I have tried using the www function to do this.

    Here is a short version of the code that I'm using.

    Code (csharp):
    1.  
    2. public const string URL = "http://someurl.com/flurryhelper.php";
    3. public const string KEY = "SOME_FLURRY_KEY";
    4.  
    5. public static void StartSession()
    6. {
    7.         WWWForm form = new WWWForm();
    8.         form.AddField("APIKey", SOME_FLURRY_KEY);
    9.         new WWW(URL, form);
    10. }
    And here is flurryhelper.php.

    PHP:
    <html>
    <head>
    <script src="https://cdn.flurry.com/js/flurry.js"></script>
    <script>alert("Hey I'm working!");</script>
    <script>FlurryAgent.startSession(' <?php echo $_POST['APIKey'?> ');</script>
    </head>
    </html>
    I need to run those scripts. Right now I'm assuming that if the alert didn't run, the other scripts also didn't run. The alert doesn't show when I run my unity web game. But when I go directly to the URL, the alert shows.

    Maybe I'm doing something wrong. Or maybe this is just not possible.