- Microlancer Beta Tester
- Author had a File in an Envato Bundle
- Lithuania
- Has been a member for 3-4 years
- Exclusive Author
- Most Wanted Bounty Winner
- Sold between 10 000 and 50 000 dollars
- Author had a Free File of the Month
- Item was Featured
Emroni, thank’s! Found it very useful 
Does anyone know if I can continue to use event tracking once I incorporate SWFADDRESS in this manner?
At the moment I am tracking “Play” events on a music player using 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”)); var pageTracker = _gat._getTracker(“xx-xxxxxxxx-x”); pageTracker._trackPageview();and then calling GA from
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;
I know this works but I’d like to implement SWFADDRESS in order to retrieve time spent on page etc but don’t want to mess up the “Play” calls I already have working.
Any links or advice greatly appreciated.
Sorry that was a long winded question!
Little clearer
This is the code I am currently using to track events and page views: 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”)); var pageTracker = _gat._getTracker(“xx-xxxxxxxx-x”); pageTracker._trackPageview();Will just changing this new code still track my events?
var _gaq = _gaq || []; _gaq.push([‘_setAccount’, ‘xx-xxxxxxxx-x’]); _gaq.push([‘_trackPageview’]); (function() { var ga = document.createElement(‘script’); ga.type = ‘text/javascript’; ga.async = true; ga.src = (‘https:’ == document.location.protocol ? ‘https://ssl' : ‘http://www') + ’.google-analytics.com/ga.js’; var s = document.getElementsByTagName(‘script’)[0]; s.parentNode.insertBefore(ga, s); })(); // Tracker for SWFAddress var pageTracker = { _trackPageview: function (url) {_gaq.push ([‘_trackPageview’, url ]);}};Try this for event tracking:
_gaq.push(['_trackEvent', 'YourCategory', 'YourAction', 'YourOptionalLabel']);If you want to do this from Flash, use this:
AS3:
// Call JS function from Flash using ExternalInterface
ExternalInterface.call("gaTrack", YourCategory, YourAction, YourOptionalLabel);
JS:
// Function to track events
function gaTrack(category, action, label){
_gaq.push(['_trackEvent',category,action, label]);
}
You can also see the guide: http://code.google.com/apis/analytics/docs/tracking/eventTrackerGuide.html
This was very helpful, thank you! However, it appears to me that the index page is sending a double visit — would you have an idea how to avoid this, without hacking the SWF to avoid sending a track on the first visit of the index page?
With older GA code, it was simple to avoid that double visit knowing that SWFAddress does send a visit to the tracker when the SWF loads:
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-XXXXXXX-X");
// pageTracker._trackPageview();
pageTracker._initData();
</script>
You could simply comment out that initial trackPageview call.
Any ideas are appreciated, thanks.
_gaq.push(['_trackPageview']);Try to comment that out (3rd line) and see what happens.
Aha, I should’ve tried that — looks like that was the ticket, thanks again!
I apologize for my ignorance but I’m not a flash programmer so I need to know where I place this code in order to track flash pages? Does it go into the main HTML page that loads the master swf or does it go into the XML pages that drive the content? I appreciate any help anyone can provide.Thanks
