views:

343

answers:

3

The organization I work for has created a small flash widget that we're encouraging supporters to place on their website. I'm trying to determine if there are ways to improve the statistics we get from those embedded widgets.

Mostly I would like to get the domain of the site that loaded the widget. Right now I'm able to see the referrer in the server logs, but that includes the full URL, and I don't want to have to write my own log processing system just to pull out domains.

I know very little ActionScript, but I've looked around the ActionScript documentation to see if I could find an obvious solution. I haven't found anything that allows the object to ask the browser for the page URL. The System.Capabilities class seems to provide a lot of information about the player's environment, but not where the player was called from (as far as I can tell, but maybe I'm missing something).

+2  A: 
Steps:
   1. Import external interface into your file: import flash.external.ExternalInterface;
   2. Initialize a variable to store the url path: var urlPath;
   3. Create a function to call external interface and assign the html page path to your variable: urlPath = ExternalInterface.call(”window.location.href.toString”);
   4. Call the function when/if needed.

Example:

With javascript: window.location.href or window.location.href.toString(); With actionscript: ExternalInterface.call(”window.location.href.toString”); External Interface html Example

Source: http://blog.circlecube.com/2008/01/02/get-current-url-to-flash-swf-using-an-external-interface-call/

To Get The Query String See This Article: http://blog.circlecube.com/2008/03/20/get-current-url-and-query-string-parameters-to-flash-tutorial/

VBNight
+1. Once you're hooked into the page's JavaScript you can then do anything you'd normally do in JavaScript, including grab/inspect the HTML in the page.
Diodeus
A: 

MochiBot is a service that does exactly this, you can either use their service (it's free) or you can take a look at the code they use (it's a ~40 line class). It's all available from their site.

A quick look in their code reveals that the bulk of what they're sending is these two:

Security.sandboxType;
Capabilities.version;
grapefrukt
+1  A: 

Yes, you can get the referrer (or anything else from the DOM for that matter). Write small javascript snippets that grab this info, and use ExternalInterface to inject these snippets into the javascript page. Then you can do ExternalInterface.call("eval", "myfunction") and have those javascript methods return data to flash.