Setup:
Goal: To track who's embedding my videos, at least with basic statistics per domain.
Since it's AS2, it's harder to do this. My idea is that I can create a PHP page which should be opened each time the player loads on any website; then 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 having user's browser open a new tab or window. Is there any hidden way to do it?
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);
?>