April 2007 - Posts
I have created an ASP.NET custom control to provide some basic functions around Google Analytics. The assembly contains two custom controls.
To use these controls please download it here. Extract the files to your system and then reference the TLaughlinGoogleAnalytics.dll from within your ASP.NET application. Once you do this you should see the TLaughlinGoogleAnalytics Components in your toolbox.
Drag and drop these controls on to your ASP.NET pages.
Analytics – Control
This control provides the function of injecting the required GoogleAnalytics script into your page. This control has only one property which is AccountNumber. Your should enter your account number here, which you get from Google. The account number looks something like UA-xxxxxx-1. You should consider adding this control to you master page, if you use master pages. This control will identify if you are using SSL or not. It will adjust the script accordingly.
AnalyticsTransaction – Control
This control records commerce transactions to Google Analytics. It should be placed on your; “Thank you for your transaction” page. You need to populate the order information and line items within your code behind page, as shown in the example below. Please note that you need to have the Analytics control on this page as well.
I hope you find this useful.
Thanks
Tim
Transaction example:
Protected Sub Page_Load(ByVal
sender As Object,
ByVal e As
System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
Dim
ObjLineItem As
Tlaughlin.google.analytics.OrderLineItem
AnalyticsTransaction1.OrderID = "22"
AnalyticsTransaction1.Affiliation =
"website"
AnalyticsTransaction1.Total = 40
AnalyticsTransaction1.Tax = 2
AnalyticsTransaction1.Shipping = 8
AnalyticsTransaction1.City = "Boston"
AnalyticsTransaction1.State = "MA"
AnalyticsTransaction1.Country = "USA"
ObjLineItem = New Tlaughlin.google.analytics.OrderLineItem
ObjLineItem.OrderID =
AnalyticsTransaction1.OrderID
ObjLineItem.Sku = "s333"
ObjLineItem.ProductName = "My First Product"
ObjLineItem.Category = "Clothing"
ObjLineItem.Price = 10.0
ObjLineItem.Quantity = 1
AnalyticsTransaction1.LineItems.Add(ObjLineItem)
ObjLineItem = New Tlaughlin.google.analytics.OrderLineItem
ObjLineItem.OrderID =
AnalyticsTransaction1.OrderID
ObjLineItem.Sku = "s112"
ObjLineItem.ProductName = "My Second Product"
ObjLineItem.Category = "Clothing"
ObjLineItem.Price = 15
ObjLineItem.Quantity = 1
AnalyticsTransaction1.LineItems.Add(ObjLineItem)
ObjLineItem = New Tlaughlin.google.analytics.OrderLineItem
ObjLineItem.OrderID =
AnalyticsTransaction1.OrderID
ObjLineItem.Sku = "s4412"
ObjLineItem.ProductName = "My Third Product"
ObjLineItem.Category = "Clothing"
ObjLineItem.Price = 5
ObjLineItem.Quantity = 1
AnalyticsTransaction1.LineItems.Add(ObjLineItem)
End If
End Sub
I seem to forget this very simple way of building a collection of class objects. Maybe it my days of VB 6, the days before inheritance. Whatever the case, if I write down maybe I will remember. If I help someone else then even better.
Create your Class, lets LineItems for an order.
Public Class OrderLineItem
Private mStrOrderID As String
Public Property OrderID() As String
Get
Return mStrOrderID
End Get
Set(ByVal value As String)
mStrOrderID = value
End Set
End Property
...
End Class
Now create a new class and Inherit from system.collection.collectionbase
Imports System.Collections
Public Class OrderLineItems
Inherits CollectionBase
Public Sub Add(ByVal pObjLineItem As OrderLineItem)
List.Add(pObjLineItem)
End Sub
Public Sub remove(ByVal pObjLineItem As OrderLineItem)
List.Remove(pObjLineItem)
End Sub
Public Function Contians(ByVal pObjLineItem As OrderLineItem) As Boolean
Return List.Contains(pObjLineItem)
End Function
Public Function indexof(ByVal pObjLineItem As OrderLineItem) As Integer
Return List.IndexOf(pObjLineItem)
End Function
Public Sub Insert(ByVal Index As Integer, ByVal pObjLineItem As OrderLineItem)
List.Insert(Index, pObjLineItem)
End Sub
Default Public Property Item(ByVal index As Integer) As OrderLineItem
Get
Dim ObjLineItem As OrderLineItem
ObjLineItem = CType(List.Item(index), OrderLineItem)
Return ObjLineItem
End Get
Set(ByVal value As OrderLineItem)
List.Item(index) = value
End Set
End Property
End Class
As you see I just OverRidde the above Propery and Sub Routines to pass a strongly typed object. Then through the magic of inheritance we get enumeration and all the other the great features of a collection. This a very simple example, but there are many areas where this can be used. As I said, I always forget this simple way of working with collections. Hopefully,no more.
In case you haven't seen it on every other Blog. Community Server 2007 has been released by Telligent. I personally have not installed and of the Community Server 2007 packages. No Beta, no RC and not RTM, yet. I am sure the platform will be great and I only wish I had more time to tinker with it as it was going through the development process.
Congratulations to all the folks over at Telligent. I am sure you are excited to have that one out the door. Plus an new store and license management for sales. Nice to see!
Enjoy, and as I go through the upgrades I promise to be a little more active in the community.
All the major search engines have announce that they are now supporting Sitemap Autodiscovery. Which boils down to an additional line you will want to add to your robots.txt file.
For Community Server 2.1 with the Google Sitemap Module installed. All I had to do was add this line to the end of my robots.txt file.
Sitemap: http://tlaughlin.pandorasystems.com/GoogleSiteMapIndex.aspx
You need to use a fully qualified domain name, unlike the Allow and Disallow lines in a Robots.txt file.
I add this today. Time will tell. Most of my traffic comes from Google. Maybe now I will see a little more from MSN, Yahoo and Ask. Who have all adopted this standard.
Back when I started this blog I had all the good intentions of keeping up with it. Adding post daily. Then of course life got in the way and I haven't posted in a while.
However, today I was doing some work with the webbrowser control in VB.NET, for a new project. Very cool control and really does a nice job exposing all of the IE object model. But my project required the accurate processing of Frames. I know frames, why! The client uses them, not my idea. I digress. So when a framset is load the DocumentCompleted event is firing for each document that makes of the entire page, or window, for consistency of the object model.
Since I really was depending of DocumentComplete to fire once so I could do my processing I really needed the solution. I asked Google, as I always do, and found a little Gem.
Private Sub WebBrowser1_DocumentCompleted( _
ByVal sender As Object, _
ByVal e As WebBrowserDocumentCompletedEventArgs _
) Handles WebBrowser1.DocumentCompleted
If Me.WebBrowser1.ReadyState = WebBrowserReadyState.Complete Then
MsgBox("Document and frames loaded!")
End If
End Sub
the key being the ReadyState Property. So simple!
I found this here http://www.developersdex.com/vb/message.asp?p=1121&r=5125510 the answer was posted by Herfried K. Wagne.
Thanks for the answer, and thanks for the motivation to actually write this post.
If you are working with the webbrowser control and have not found it yet check out Working with the Web Browser Control in Visual Studio 2005 - IE7Clone. A great how to resource with nice example application.