views:

270

answers:

3

Setup:

  • an online tv channel with "youtube" like clips and categories
  • our own flash video player which can be embeded into other remote sites
  • as2 flash player

Goal: To track who's embeding my videos, at least with basic statistics per domain.

Since it's AS2, it's harder to do this. My ideea is that I can create a php page which should be opened each time the player loads on any website; than the flash player can do a "geturl" of the php file which has Google Analytics code or some other decent tracker.

The geturl command could contain a variable like the Video Title which already is included in the player; and this title would pass on with GET to the php file and setup a dynamic page title which can be tracked very well.

Problem: how to i use the GETURL function without have user's browser open a new tab or window. Is there any hidden way to do it?

A: 

The easiest way to do this is to use LoadVars:

var lv:LoadVars = new LoadVars();

lv.var1 = "hostname";
lv.var2 = "browsersettings";

lv.send("http://yourserver/script.php, lv, "POST");

I'm not really sure if there are any Sandbox-restrictions for this.

Pbirkoff
thanks! I'll be posting the results tomorrowMost restrictions are off. I had to turn the off so the player could be embeded offsite and load some xml files from the homesite.
Dragomir Dan
Sorry for not posting. I wanted to wait for some stats to gather. After a few days I realised that Mochibot only tracks .swf file hosts and not all the websites which embeded the .swf remotely. I want to try the loadvars method soon, but I must now first if there really is a "global" type variable in AS2 which can collect the domain name of the site where the SWF is played. "hostname" could be, but I'm just trying to be sure before the testing starts.Hope there is such a thing...
Dragomir Dan
You can get the domain name with the following command: var pageURL:String = ExternalInterface.call('window.location.href.toString');
Pbirkoff
Pbirkoff, sorry for the really late reply, but it doesn't work. There was the missing " from the send php file, but that's not the real problem. I'm not sure how I can find out, but the functionality of the player has been compromised when the code is in:var lv:LoadVars = new LoadVars();lv.var1 = "hostname";lv.var2 = "browsersettings";lv.send("http://www/t.php", lv, "POST");I placed it at the bottom of the script. Would that interfere?
Dragomir Dan
Also it does not manage to communicate with the php script. I made the following php file: if ( isset( $_POST['lv'] ) ) {$lv = $_POST['lv'];$lv = " <h1>".$lv."</h1> \n"; $f = 'tracked.html';$of = fopen($f, 'w');fwrite ($of, $lv); fclose ($of);
Dragomir Dan
the html file doesn't get created (I test it by switching to GET method, which works) .... sorry for pasting the code like that, but I'm not sure I can insert bbcode here
Dragomir Dan
I am experimenting now with the php side and using sendAndLoad function instead of send
Dragomir Dan
please check out my own answer for the follow up
Dragomir Dan
A: 

Salut Dan,

Haven't done as2 in a while.

mochi bot

I remember I used mochibot, you could track your swf, wherever it might be embedded.

They might still have the as2 tracking.

George Profenza
Thank you, mochibot is nice for starters and it does have an AS2 script too
Dragomir Dan
Nicio problema Dan :) bun venit pe stackoverflow. Nu uita sa votezi/bifezi raspunsurile de care multumit :)
George Profenza
Sorry for not posting. I wanted to wait for some stats to gather. After a few days I realised that Mochibot only tracks .swf file hosts and not all the websites which embeded the .swf remotely.
Dragomir Dan
A: 

The main problem I found is that control over the external information can only exist if there is allowScriptAccess in the html embed code of the , like this:

<param name="allowScriptAccess" value="always">

and

allowScriptAccess="always"

In the tag.

This is a bit late for me since I can't tell everyone who embeds my player to add those lines to their site, but from now on... Anyway, someone who wants to hide can easily just delete the lines. So I renamed the SWF file ... and now everyone who does the remote embed has to check back and get the new code.

Here's the AS2 code that worked:

function geturlhttp() {
//urlPath = ExternalInterface.call("window.location.href.toString");
urlPath = ExternalInterface.call("eval","document.location.href");

//both work, try which one is bet
}
geturlhttp();


var lv:LoadVars = new LoadVars();

lv.var1 = urlPath;
lv.var2 = title; //an internal variable, the name of the file


lv.sendAndLoad("http://www.somesite.test/tracker.php",lv,"POST");

So the tracking only works on my own site, not the external remote embedding sites which come up empty or "null" in sql.

And here's the PHP code I made with SQL. I've only made something for the insertion and I'm going to work on display and selection later...

<?php
//POST needs to be secured, this is just a test :)
$url = $_POST['var1'];
$title = $_POST['var2'];

$dbhost = "127.0.0.1"; // almost always localhost.
$dbname = "x";   // Database Name, In our case, its news
$dbuser = "x"; // Database Username
$dbpass = "x"; // Databse Password


$connect = mysql_connect("$dbhost","$dbuser","$dbpass");// Connecting to Database

mysql_select_db($dbname) or die (mysql_error()); // Selecting Database

$sql= "INSERT INTO tablename (urlrow, titlerow) VALUES ('$url','$title')";
$result = mysql_query($sql);

?>
Dragomir Dan
And here's some more food for thought: can a dynamic url be used in the SRC information for the flash EMBED tag? If so, could this dynamic url be used for tracking...
Dragomir Dan
Oh yeah, I remembers my first idea, at least for content statistics... making a php file with html title and body based on the dynamic variables sent from the swf player ...and placing a google analytics code inside, so I get the content usage by page title. (URL can be dynamically generated but it will probably involve mod_rewrite).
Dragomir Dan
Sorry for the typos... it was really late :)
Dragomir Dan