Slight improvement Google Analytics

This is a forum to suggest new features for mojoPortal. 

This thread is closed to new posts. You must sign in to post in the forums.
3/11/2010 11:46:44 AM
Gravatar
Total Posts 171
I am a Russian programmer

Slight improvement Google Analytics

Hi, Joe
Slight improvement for Google Analytics:

1) According

http://code.google.com/intl/ru-RU/apis/analytics/docs/gaJS/gaJSApiBasicConfiguration.html#_gat.GA_Tracker_._initData

_initData()Deprecated. initData() now executes automatically in the ga.js tracking code.

Therefore, from

GoogleAnalyticsScript.cs
private void SetupTracker()

you can delete these lines:
script.Append(trackerName + "._initData();");
script.Append("\n");


2) According

http://code.google.com/intl/ru-RU/apis/analytics/docs/gaJS/gaJSApiBasicConfiguration.html#_gat.GA_Tracker_._setVar
_setVar(newVal) deprecated. This function is changed to: _setCustomVar(index, name, value, opt_scope)
The page also has a detailed example: http://code.google.com/intl/ru-RU/apis/analytics/docs/tracking/gaTrackingCustomVariables.html

I think we fit option: Session-level Custom Variables and therefore (but I'm not sure)

private void SetupUserTracking(StringBuilder script)

script.Append(trackerName + "._setVar(\"" + memberLabel + "\");");
change to:
script.Append(trackerName + "._setCustomVar(1, \"User Type\", \"" + memberLabel + "\", 2);");

And as I understood from the above article should once again call _setCustomVar()

3) According:
http://code.google.com/intl/ru-RU/apis/analytics/docs/gaJS/gaJSApiDomainDirectory.html#_gat.GA_Tracker_._setAllowHash

 _setAllowHash() Default value is true.

therefore:

private bool setAllowHashFalse = false;
change to
private bool setAllowHashFalse = true;

and

private void SetupTracker()
script.Append(trackerName + "._setAllowHash(true);");

change to
script.Append(trackerName + "._setAllowHash(\"false\");");

Best regards, Alexander


 

3/12/2010 1:14:13 PM
Gravatar
Total Posts 18439

Re: Slight improvement Google Analytics

Hi Alexander,

I agree with your suggested changes and will get to them soon.

Best,

Joe

3/13/2010 4:56:36 AM
Gravatar
Total Posts 171
I am a Russian programmer

Re: Slight improvement Google Analytics

Thanks, Joe

And more about Google Analytics

1) In all the examples use analytics code has the form

http://code.google.com/intl/ru-RU/apis/analytics/docs/tracking/gaTrackingOverview.html

try{
var pageTracker = _gat._getTracker("UA-xxxxxx-x");
pageTracker._trackPageview();
} catch(err) {}

Probably need to add the following lines to private void SetupTracker()

script.Append("try{"); script.Append("\n");

........

script.Append("} catch(err) {}"); script.Append("\n");

 

2) The new version of Google Analytics supports Asynchronous Tracking (Has been released December 1, 2009)

Unlike a traditional installation, asynchronous tracking optimizes how browsers load ga.js so its impact on user experience is minimized. It also allows you to put your Analytics snippet higher in the page without delaying subsequent content from rendering.
 

About how to move from traditional to an asynchronous code:

http://code.google.com/intl/ru-RU/apis/analytics/docs/tracking/asyncMigrationExamples.html


It's easy, but it would require changes in many places in GoogleAnalyticsScript.cs and layout.Master
 

Best regards, Alexander

3/14/2010 11:32:40 AM
Gravatar
Total Posts 18439

Re: Slight improvement Google Analytics

Hi Alexander,

Yes, I have seen that as I subscribe to the Google Analytics blog.

There are several challenges to changing to this async model, the best we could do easily is implement the split script approach mentioned here:

http://code.google.com/intl/ru-RU/apis/analytics/docs/tracking/asyncUsageGuide.html#SplitSnippet

which retains most of the benefits of the async approach.

The other issue is backward compatibility for existing sites which may have javascript snippets already entered in the content system for custom tracking. For example I have many places where I track things like referrals to consulting partners and other external links where I have added javascript to the link to track the click like this for example:

<a class="fn org url" href="http://i7media.net/mojoPortal.aspx" onclick="mojoPageTracker._trackPageview('/ReferToi7Media.aspx');window.open(this.href,'_self');return false;">i7 Media</a>

so it would be problematic for me to find all these in my content and replace with the new async syntax and others may also have existing tracking snippets.

What I am willing to do is make 2 new controls GAnalyticsAsyncTop and GAnalyticsAsyncBottom so we can implement an option for the async approach without breaking any existing tracking using the old approach. I will let you know when these controls are ready and you could test for me since I do not want to change my site. The idea would be to remove the existing one and replace it with the bottom control and also add the top control just after the opening form tag in layout.master.

I have not had any problems using the traditional approach and I think this async approach is a micro optimization. Recently I watched all the videos on the googleanalytics channel on YouTube http://www.youtube.com/googleanalytics I learned a lot that helped me get better reporting, especially about advanced segments. I highly recommend watching all these as they were very helpful. But one thing I noticed is they mentioned how they soft launched the new async script approach but are not pressing hard for people to change to it and they will never get rid of the traditional way. But in any case I will try to implement support for it with the 2 new controls and hope that you can test it when it is ready and make sure it works correctly.

Best,

Joe

3/14/2010 3:43:22 PM
Gravatar
Total Posts 171
I am a Russian programmer

Re: Slight improvement Google Analytics

Hi, Joe!
 

Thanks for the link, I'll watch. Subject Google Analytics is interest for me. Recently I read a collection of articles about it in Russian.

Yes, you are right for compatibility with older versions, you need to do another component. But I think that  the old component must make changes, which I wrote above.

And I think that we need to make changes to mojoGoogleAnalyticsScript.cs
CustomerLabel = Resource.AnalyticsCustomer;
This is not correct. CustomerLabel should not be taken from the resource file. It should not depend on the language system. Otherwise HasGALabelCookie of GoogleAnalyticsScript.cs will not work correctly.

And I do not like the logic work of HasGALabelCookie. 

Best regards, Alexander
 

3/14/2010 4:54:11 PM
Gravatar
Total Posts 18439

Re: Slight improvement Google Analytics

Hi Alexander,

I've already made most of the changes but have not yet merged it to trunk, it should be there by tomorrow night.

I came to the same conclusion after learning more about analytics and looking at my reports, I should not be using resource files for those labels. My intention was for it to be possible to localize the labels, but on my site where I'm not forcing a specific culture I get a mix of labels based on the user browser language. I will make those come from Web.config settings so they can be customized as needed but will be constant for a site.

I have an idea for  a change for the cookie logic as the user may not always have the cookie if they come from a different machine, so it is not optimal. My intention is to flag authenticated users as members, user's who have made transactions in my store as customers, and admins as admins, but currently a customer who signs in from a different machine is flagged as member. I need to change to have the logic in mojoGoogleAnalytics instead so I can just check the siteuser object for TotalRevenue and check if he is in Admins role to determine the memberType label, then I will not need a separate customerLabel property and I will not need the cookie check at all.

I really enjoyed those videos on YouTube and next plan to study the resources at Conversion University: http://www.google.com/support/conversionuniversity/?hl=en

The things I still want to understand better is setting goals and using the funnel reports to improve conversion rates. I think there is some challenges when using external payment providers like PayPal and Google Checkout because the user leaves the site to make payment and if it takes more than 20 minutes for them to return then it is seen as a new session that completes the order and the old session looks like they abandoned the funnel. So this makes it difficult to get a good understanding of the user behavior. What happens is that orders take a while for the payment to clear and only after it clears do they get the confirmation email with a link to the order detail and that is where the transaction is logged to google analytics. So we get a session that looks like the user left the site without completing the funnel and then we get a session that looks like the user came out of nowhere and completed a transaction but they are not the same session from analytics point of view so the funnel report cannot connect the dots between the separate sessions. One solution that comes to mind is to send an initial email as soon as the order is received and make a link to the order detail so the user does come back to the site right away and we can track the transaction sooner but show the user on the order detail and in the initial email that the order is received but payment is still being processed. Then when payment clears send another confirmation so the user can download the products. These issues may not affect you or be of interest if you are not using the WebStore feature but the ecommerce reporting in google analytics is very interesting to me since I am trying to figure out how to improve ecommerce conversion rate on my store.

Best,

Joe

 

3/15/2010 9:52:51 AM
Gravatar
Total Posts 171
I am a Russian programmer

Re: Slight improvement Google Analytics

Hi, Joe!


I have never dealt with e-commerce and now work in government offices. Therefore, we do not sell over the Internet. Therefore, types of visitors to the site of interest to me, because I want to know how many people actually visits the site without administrators and editors of the site. To do this, and to fix the types of visitors. And as detailed as possible. Something to draw conclusions on the basis of these data.

Expect you to change, to test them!

Best regards, Alexander

3/16/2010 8:24:22 AM
Gravatar
Total Posts 18439

Re: Slight improvement Google Analytics

Hi Alexander,

The new controls for Async google analytics have landed in svn if you want to test them.

remove the <portal:mojoGoogleAnalyticsScript from your layout.master and then put this at the top just below the opening body tag

<portal:AnalyticsAsyncTopScript id="analyticsTop" runat="server" />

then add this just before the closing body tag

<portal:AnalyticsAsyncBottomScript ID="analyticsBottom" runat="server" />

If you discover any errors in these controls while testing please feel free to modify those controls and send me the changes. The controls are located under Web/Controls/Analytics.

I've also updated the regular googleAnalytics control.

Best,

Joe

3/16/2010 9:40:04 AM
Gravatar
Total Posts 171
I am a Russian programmer

Re: Slight improvement Google Analytics

Thank you, Joe

I get it from SVN and testing it now.

Change (you need to take in quotes)

script.Append(trackerName + "._setAllowHash(false);");

to

script.Append(trackerName + "._setAllowHash(\"false\");");

and more

Why set the script Google Analytics in the forms: FileDialog.aspx and ImageCropperDialog.aspx?

Best regards, Alexander

3/16/2010 10:51:59 AM
Gravatar
Total Posts 18439

Re: Slight improvement Google Analytics

Hi Alexander,

The function _setAllowHash takes a boolean not a string therefore it does not need quotes. The documentation does show quotes in one place but I believe that is an error in the documentation as most places in the documentation do not show quotes around boolean parameters passed to functions and javascript has a boolean data type represented by true and false and typically in javascript you don't put quotes around boolean variables.

http://code.google.com/apis/analytics/docs/tracking/gaTrackingSite.html

http://code.google.com/apis/analytics/docs/gaJS/gaJSApiDomainDirectory.html#_gat.GA_Tracker_._setAllowHash

I track dialog page views the same as any other because I want to record all viewed pages. I see no reason why a dialog should be treated differently.

Best,

Joe

3/16/2010 11:15:00 AM
Gravatar
Total Posts 171
I am a Russian programmer

Re: Slight improvement Google Analytics

Thank you, Joe

If the quotes are not available, then get an error in IE in ga.js. You can try it.

and more

There is another useful function_addOrganic

http://code.google.com/intl/ru-RU/apis/analytics/docs/gaJS/gaJSApiSearchEngines.html#_gat.GA_Tracker_._addOrganic

Can you add it?

Best regards, Alexander

3/16/2010 12:54:34 PM
Gravatar
Total Posts 18439

Re: Slight improvement Google Analytics

Hi Alexander,

I get no script errors in IE 8 when I try using an overridedomain and sethash = false. I suspect it has something to do with either browser settings for script debugging or with hosting the ga.js file yourself. I believe the code is correct without quotes and would be incorrect with them.

Maybe I will look into adding the _addOrganic at some point but not now as I've already spent way more time on Google Analytics this week than planned and other things I need to do have not been accomplished. 

Since _addOrganic could be called multiple times for multiple additional search engines, it does not seem like an easy thing to add. You can just as easily add javascript to the page/layout.master yourself to accomplish this, especially with the new async version, you can add a script block of your own that does

_gaq.push(['_add_Organic','somesearchengine.com', 'somekeyword', false]);

Best,

Joe

3/16/2010 1:03:27 PM
Gravatar
Total Posts 171
I am a Russian programmer

Re: Slight improvement Google Analytics

Hi, Joe

You can just as easily add javascript to the page/layout.master yourself to accomplish this, especially with the new async version, you can add a script block of your own that does

_gaq.push(['_add_Organic','somesearchengine.com', 'somekeyword', false]);

I'll go that way

Best regards, Alexander

3/17/2010 10:56:26 AM
Gravatar
Total Posts 171
I am a Russian programmer

Re: Slight improvement Google Analytics

Hi, Joe

Fix:

1) delete mojoGoogleAnalyticsScript.cs from Web\Controls

For GoogleAnalyticsScript.cs :

2) script.Append("} catch(err) {}");
be called after _trackPageview();

3) SetupUserTracking(script);

must be called before _trackPageview();

Best regards, Alexander

3/17/2010 11:12:08 AM
Gravatar
Total Posts 171
I am a Russian programmer

Re: Slight improvement Google Analytics

and more

script.Append(trackerName + "._setCustomVar(1, \"" + memberLabel + "\", \"" + memberType + "\", 1);");
to

script.Append(trackerName + "._setCustomVar(1, \"" + memberType + "\", \"" + memberLabel + "\", 1);");
 

Best regards, Alexander

3/18/2010 11:21:55 AM
Gravatar
Total Posts 171
I am a Russian programmer

Re: Slight improvement Google Analytics

Hi, Joe

I have a small question. Why do you separate the code try{} catch(err) {} in two parts?

I have not seen that would have been done in the examples, and as far as I know try{} catch(err) {} has a large overhead.

And more

The code if(_gat != undefined) was needed in older versions of the Google Analytics, but now it is superfluous.

Best regards, Alexander

P.S. Now I'm testing Asynchronous tracking....

3/18/2010 1:58:29 PM
Gravatar
Total Posts 171
I am a Russian programmer

Re: Slight improvement Google Analytics

mistake in Asynchronous tracking

AnalyticsAsyncTopScript.cs

place

SetupUserTracking(writer);

before

if (pageToTrack.Length > 0)
{
writer.Write(" _gaq.push(['_trackPageview','" + pageToTrack.Replace("'", string.Empty).Replace("\"", string.Empty) + "']); ");
}
else
{
writer.Write(" _gaq.push(['_trackPageview']); ");
}

 

and change SetupUserTracking(HtmlTextWriter writer) to

if (string.IsNullOrEmpty(memberLabel)) { return; }

writer.Write("_gaq.push(['_setCustomVar', 1, '" + memberType + "', '" + memberLabel + "', 1]);");
writer.Write("\n");


AnalyticsAsyncBottomScript.cs

place

if (WebConfigSettings.GoogleAnalyticsScriptOverrideUrl.Length > 0)
{
OverrideScriptUrl = WebConfigSettings.GoogleAnalyticsScriptOverrideUrl;
}

before

// let Web.config setting trump site settings. this meets my needs where I want to track the demo site but am letting people login as admin
// this way if the remove or change it in site settings it still uses my profile id

and

change

writer.Write("ga.src = '" + overrideScriptUrl + ":';");

to

writer.Write("ga.src = '" + overrideScriptUrl + "';");

Best regards, Alexander

3/19/2010 3:20:29 AM
Gravatar
Total Posts 171
I am a Russian programmer

Re: Slight improvement Google Analytics

Thank you, Joe

I examined all parts of the code and everything is working correctly, except for one piece of code

AnalyticsAsyncTopScript.cs

add quote after _setCustomVar

writer.Write("_gaq.push(['_setCustomVar', 1, '" + memberType + "', '" + memberLabel + "', 1]);");
 

Excellent work, Joe! Congratulations!

Best regards, Alexander

3/20/2010 7:10:21 AM
Gravatar
Total Posts 18439

Re: Slight improvement Google Analytics

Hi Alexander,

Thanks for your help in testing the new async controls and finding my mistakes.

Best,

Joe

You must sign in to post in the forums. This thread is closed to new posts.