Hi,
I created a web site in Actionscript 2 and have been asked to add Google Analytics to it. This is the first person who has asked me to do this and when I log into Google Analytics, they only provide the code for Actionscript 3. Apparently there used to be just Actionscript 2 code there but for a while it has just been AS3. I am told that the old code still works and I know that someone out there must have it. Can anyone help me out with it?
Thank you,
-Jan
Hi,
I am not seeing any results from using the code from the blog. My navigation code looks like this:
import flash.external.*;
#include "logging.as"
bt_video.onRelease = function() {
trackGA("swfLoaded");
unloadMovieNum (2);
unloadMovieNum (3);
unloadMovieNum (4);
unloadMovieNum (8);
unloadMovieNum (10);
loadMovieNum ("AS2MR_bio.swf",2);
loadMovieNum ("AS2MR_bioWRD.swf",3);
loadMovieNum ("AS2MR_BOTNAV_02.swf",7);
};
I used the .as file that they had to download using my tracking code number and I included the code within the html page that they recommended.
Thanks,
-Jan
//trackGA (categoryOrPageTrack [required], action [required], label [optional], value [optional]
//categoryOrPageTrack - either the category string or a string saying 'page'
function trackGA(categoryOrPageTrack:String, action:String, optional_label:String, optional_value:Number) {
//call page tracking version of Google analytics
if (categoryOrPageTrack == "page") {
//trace("GATC pageTracker call");
trackGAPage(action);
}
//call event tracking method
else {
//trace("GATC event tracker call");
trackGAEvent(categoryOrPageTrack, action, optional_label, optional_value);
}
}
var prefix:String = "flashGA";
//Google Analytics Calls Page Tracking - for tracking page views
function trackGAPage(action:String) {
//GA call
if (prefix != null && !eventTrack){
var call = "/" + prefix + "/" + action;
//Old Google Analytics Code (urchinTracker)
ExternalInterface.call("urchinTracker('"+call+"')");
//New Google Analytics Code (_trackPageview) pageview
ExternalInterface.call("pageTracker._trackPageview('"+call+"')");
trace("==GATC==pageTracker._trackPageview('"+call+"')");
}
_root.tracer.text = action;
}
//Google Analytics Event Tracking Calls - for tracking events and not pageviews
//category, action, label (optional), value(optional)
function trackGAEvent(category:String, action:String, optional_label:String, optional_value:Number) {
/*
objectTracker_trackEvent(category, action, optional_label, optional_value)
category (required) - The name you supply for the group of objects you want to track.
action (required) - A string that is uniquely paired with each category, and commonly used to define the type of user interaction for the web object.
label (optional) - An optional string to provide additional dimensions to the event data.
value (optional) - An optional integer that you can use to provide numerical data about the user event.
*/
theCategory = "'" + category;
theAction = "', '" + action + "'";
theLabel = (optional_label == null) ? "" : ", '" + optional_label + "'";
theValue = (optional_value == null) ? "" : ", " + optional_value;
//New Google Analytics Code (_trackEvent) event tracking
theCall = "pageTracker._trackEvent(" + theCategory + theAction + theLabel + theValue + ")";
ExternalInterface.call(theCall);
trace("====GATC===="+theCall);
_root.tracer.text = theCategory + theAction + theLabel + theValue;
}
<SCRIPT type=text/javascript>
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</SCRIPT>
<SCRIPT type=text/javascript>
var pageTracker = _gat._getTracker("UA-########");
pageTracker._initData();
pageTracker._trackPageview();
</SCRIPT>
<script language="javascript">AC_FL_RunContent = 0;</script>
<script src="AC_RunActiveContent.js" language="javascript"></script>
The complete code for the top navigation:
import flash.external.*;
#include "logging.as"
btn_logo2.onRelease = function() {
trackGA("page","swfLoaded");
unloadMovieNum (2);
unloadMovieNum (3);
unloadMovieNum (4);
unloadMovieNum (7);
unloadMovieNum (10);
loadMovieNum ("AS2MR_home.swf",2);
loadMovieNum ("AS2MR_homeWRD.swf",3);
loadMovieNum ("AS2MR_BOTNAV_01.swf",8);
trackGA("button/pressed/home");
};
btn_home.onRelease = function() {
trackGA("page","swfLoaded");
unloadMovieNum (2);
unloadMovieNum (3);
unloadMovieNum (4);
unloadMovieNum (7);
unloadMovieNum (10);
loadMovieNum ("AS2MR_home.swf",2);
loadMovieNum ("AS2MR_homeWRD.swf",3);
loadMovieNum ("AS2MR_BOTNAV_01.swf",8);
trackGA("button/pressed/home");
};
btn_video.onRelease = function() {
trackGA("page","swfLoaded");
unloadMovieNum (2);
unloadMovieNum (3);
unloadMovieNum (4);
unloadMovieNum (7);
unloadMovieNum (10);
loadMovieNum ("AS2MR_videos.swf",2);
loadMovieNum ("AS2MR_BOTNAV_01.swf",8);
trackGA("button/pressed/video");
}
btn_work.onRelease = function() {
trackGA("page","swfLoaded");
unloadMovieNum (2);
unloadMovieNum (3);
unloadMovieNum (4);
unloadMovieNum (7);
unloadMovieNum (10);
loadMovieNum ("AS2MR_work.swf",2);
loadMovieNum ("AS2MR_workWRD.swf",3);
loadMovieNum ("AS2MR_BOTNAV_01.swf",8);
trackGA("button/pressed/work");
}
btn_bio.onRelease = function() {
trackGA("page","swfLoaded");
unloadMovieNum (2);
unloadMovieNum (3);
unloadMovieNum (4);
unloadMovieNum (8);
unloadMovieNum (10);
loadMovieNum ("AS2MR_bio.swf",2);
loadMovieNum ("AS2MR_bioWRD.swf",3);
loadMovieNum ("AS2MR_BOTNAV_02.swf",7);
trackGA("button/pressed/bio");
};
The blog that you sent was updated at this link:
They summarize the string for tracking:
_trackEvent(category, action, optional_label, optional_value)
category:string (required)
This is the name of the object you are tracking.
action:string (required)
This is the action that happens to your object you want to track.
optional_label:string (optional)
This can be more information to accompany the action.
optional_value:integer (optional)
A number to provide numerical information to accompany the action.
I followed the steps they posted but I'm missing some key element. Some basic piece of information is not penetrating my head...
I downloaded the sample files and that confused me further... I'm pathetic... ![]()
I made adjustments by adding the tracking code to each page as opposed to the navigation.
This is so frustrating. The Awstats picks up the swf files as well as the flv files without any additions to the code. The raw logs show all the files, swf and flv included. Why is Google Analytics so backwards that you have to jump through hoops writing code to track the swf and flv files. The owner of the web site is used to looking at the Google Stats and wants to use those. I am just really getting annoyed at this. The code is pinging the Google Stats but there is no differentiation from one swf to the next. This is so frustratingg!
Even with the sample files, I am still unable to get this right. I still don't understand why Google Analytics can't track .swf and .flv files the way other stat programs can... I am a designer so this is very frustrating to me. I get no answers at all from Google... i see .swf and .flv in the raw data files so I don't understand why Google chooses to ignore those.
this is how the GA is tracking:
| 829 | 734 | 00:00:43 | 69.07% | 65.86% | $0.00 | ||
| 2. | 384 | 134 | 00:00:46 | 100.00% | 33.07% | $0.00 | |
| 3. | 311 | 78 | 00:00:33 | 0.00% | 19.94% | $0.00 | |
| 4. | 1 | 1 | 00:00:00 | 100.00% | 100.00% | $0.00 | |
| 5. | 1 | 1 | 00:00:00 | 100.00% | 100.00% | $0.00 |
This is how the Awstats is tracking:
| Viewed | Average size | Entry | Exit |
/index | 1070 | 5.86 KB | 959 | 836 |
51 | 2.20 MB | 1 | 23 | |
41 | 26.97 MB |
| 16 | |
36 | 23.98 MB | 1 | 17 | |
31 | 102.42 KB |
| 9 | |
21 | 121.90 KB |
| 5 | |
19 | 42.89 MB | 1 | 7 | |
19 | 90.58 KB |
| 13 | |
16 | 3.57 MB | 1 | 7 | |
16 | 15.95 KB | 1 | 3 | |
15 | 21.79 MB | 1 | 7 | |
12 | 176.22 KB |
| 3 | |
11 | 98.42 KB | 1 |
| |
10 | 4.90 MB |
| 4 | |
9 | 171.19 KB |
| 4 | |
9 | 24.78 MB |
| 2 | |
7 | 23.98 MB |
| 3 | |
7 | 4.53 MB | 1 | 4 | |
6 | 16.33 MB |
|
| |
4 | 15.27 MB | 1 | 1 | |
3 | 29.54 MB |
| 2 | |
3 | 26.97 MB |
| 2 | |
1 | 23.98 MB |
| 1 |
North America
Europe, Middle East and Africa
Asia Pacific