I’ve had this question a couple of times over the last week so here’s some info on how to determine the domain from which a Brightcove Player is loaded. I’ve used the Brightcove sample code for reporting into Google Analytics. This approach is especially handy if you want to plug in some custom analytics & reporting for syndicated players, and you don’t want to modify the standard publishing code generated by Brightcove Studio.

This article assumes you have read the Brightove Help Topic on Developing an analytics SWF, and builds on the Brightcove example code for  creating a Google Analytics SWF. An analytics SWF is a non-visual Flash component that you can use to fire and collect events relating to video and player performance. You can use the Publishing module to configure a Brightcove player to use an analytics SWF. You can also customize a player template so that all players using the template use the analytics SWF. You can develop specialized analytics SWFs to work with any number of web and video analytics solutions.

You can use the Brightcove sample zip code as a starting point to report the page URL to Google. Go through the example as described on the help page, until you come to the section that will fire off an event to Google. You could change this code portion to the following:

public function fireEvent(eventName:String):void
{
    var experienceId:Number  = _bcExperience.getExperienceID();
    var action:String = "";

    if (eventName == EVENT_PLAYER_LOAD)
    {
        var experienceURL:String = _bcExperience.getExperienceURL();
        var referrerURL:String = _bcExperience.getReferrerURL();
        action = "'expid=" + experienceId + "/url=" + experienceURL + "/refurl=" + referrerURL + "/" + eventName;
    }
    else
    {
        var video:Object = _bcVideo.getCurrentVideo();
        var playlistId:Number  = video.lineupId;
        var videoId:Number   = video.id;
        action = "'/expid=" + experienceId + "/plid=" + playlistId + "/vid=" + videoId + "/" + eventName;
    }
    ExternalInterface.call("pageTracker._trackPageview",action);
}

As you can see,

_bcExperience.getExperienceURL()

retrieves the URL in which the player is embedded and adds it to the call string to Google Analytics.

Now if  you only want the domain name of the page or another portion of the URL, then use this nifty little class:

package com.urltools
{
    import flash.external.ExternalInterface;

    public class URL
    {
        private static const PROTOCOL:RegExp = /^[a-zA-Z]*(?=:)/g;
        private static const HOST:RegExp = /(?<=:)\/\/(\w|\.)+.(\w){3}\/*/g;
        private static const PORT:RegExp = /(?<=:)(\d)+/g;

        private var _url:String;
        public function get url():String { return _url; }

        /**
         * Returns the protocol of the url.
         */

        public function get protocol():String
        {
            return url.match( PROTOCOL )[0];
        }

        /**
         * Returns the host domain of the url.
         */

        public function get host():String
        {
            return url.match( HOST )[0];
        }

        /**
         * Returns the port number of the url.
         */

        public function get port():int
        {
            return int(url.match( PORT )[0]);
        }

        private var _queryString:QueryString;
        public function get queryString():QueryString { return _queryString; }

        /**
         * A URL object represents and provides methods for working
         * with a URL string.
         */

        public function URL( url:String )
        {
            _url = url;

            if ( url.indexOf( '?' ) != -1 )
                _queryString = new QueryString( url.split( '?' )[1] );
        }

        /**
         * Returns the URL string the URL object represents.
         */

        public function toString():String
        {
            return _url;
        }

        /**
         * Returns a URL object which represents the URL of the html page
         * of the embedded swf.  This URL contains all query string, and anchor information.
         */

        public static function getPageURL():URL
        {
            return new URL( Application.application.url );
        }
    }
}
 

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>