Developer Forum »
WAFMetrics.Trackings
5 posts

What is needed to use WAFMetrics correctly?

I have made a CustomWebForm and made the method:

public override void OnSubmit(WebFormSubmit submit)

    {

        base.OnSubmit(submit);

        if(!string.IsNullOrEmpty(this.GoogleScript)){

            TrackingVariable t = new TrackingVariable();

            t.Value = this.GoogleScript;

            WAFMetrics.Trackings.Add(t);

        }

 

    }

It is a Webforms solution.

this.GoogleScript is a short string and has a value : «_gaq.push(['_trackEvent',  'Bli Frivillig', 'Frivillig', 'Takk'])».

 

120 posts

Hi, the WAFMetrics allows you to add additional tracking data for Google Analytics. The system is only compatible with webforms, and it is only active when you are not logged in in edit. (Either log out of edit using the log out button or close all browser window, before you open a new one, to make sure the edit session is not active.)

During a page view Webnodes collects all tracking information that is going to be sent to google in the WAFMetrics.Tracking collection. This collection is uniquely associated with the current pageview. The collections contains instances of classes that implements the abstrackt class ITracking. At the end of the page view, Webnodes will call the "GetScript" method of each ITracking collected and insert the necessary google analytics javascript code at the end of the HTML document.

There are several built in classes that implements the ITracking interface. The most obvious is the PageViewTracking class. An instance of this is automatically added to every pageview.

Other built in classes:
TrackingVariable ( calls the "pageTracker._setVar" google method )
EcomerceTracking ( calls the "pageTracker.__addTrans" etc. google methods )

You can add your own if you want to, just inherit from ITracking.

 

120 posts

Se the enclosed source code for the tracking http://www.webnodes.no/WAFMetrics?pid=Native-ContentFile-File

 

Here is sample implementation: (not tested, you probably need to double check the javascript...)

public partial class _Default : System.Web.UI.Page {
    class ScriptTracking : ITracking {
        string _script;
        public ScriptTracking(string script) {
            _script = script;
        }
        public override void BuildScript(StringBuilder sb, bool isAjaxCall) {
            sb.AppendLine(_script);
        }
    }
    protected void Page_Load(object sender, EventArgs e) {
        WAFMetrics.Trackings.Add(new ScriptTracking("pageTracker.push(['_trackEvent',  'Bli Frivillig', 'Frivillig', 'Takk'])"));
    }
}

 

 

1