November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
This Developer Guide describes how to develop customized solutions to Episerver Google Analytics for your website. To be able to follow these instructions, download the Sample Package Google Analytics for EPiServer.
This document describes how to create graphs and lists displayed in the Google Analytics gadget and action window.
Google Analytics metrics can be either graphs or lists. The following base classes define the kind of metric:
These metrics can be registered for the dashboard or the action panel using attributes. Event metrics cannot be displayed in the action panel.
You can look how the configuration example in AlloyTechConfig.xml is done as a Shell module, see AlloyTechConfig.xml:
Graph metrics display a value over time. The dimension (x-axis) is either day, week or month and is selected by the user, other metric (y-axis) is defined by the graph metric code.
Create a graph metric in Visual Studio as follows:
See the example in Metrics.cs, block1.
A special case of the graph metric is an event metric. This assumes an event is tracked on the site. Refer to the tracking documentation on information on how to track events.
See the example in Metrics.cs, block2.
A list metric displays a list of labels and an associated value. For example most visited pages.
Create a graph metric in Visual Studio as follows:
See the example in Metrics.cs, block3.
It is possible to create the query object used to query Google for values by implementing the ICustomQueryBuilder interface. This allows to define more complex queries than regular usage (above).
See the example in Metrics.cs, block4, about how to create a custom graph query.
See the example in Metrics.cs, block5, about how to create a custom list query.
It is possible to completely bypass querying Google for result and instead generating results in code. This allows to return any values for the graphs and lists. To do this implement ICustomResultFactory>TResult< on a metric implementation.
See the example in Metrics.cs, block6, about how to create a custom graph result.
See the example in Metrics.cs, block7, about how to create a custom list result.
The Google Analytics module provides an API for adding graphs and lists to the dashboard. This API uses the Google Query API to retrieve data.
This document describes how to access the login token entered by users or adminsitrator to query Google directly and using outside of the dashboard or action panel.
See Prerequisites above.
To retrieve data from Google a login token and a table ID corresponding to a tracked web site are required. See the example in Querying.cs, block1, how the login token configured by an administrator or user is retrieved.
Also needed for the query is a table ID. The table ID corresponds to a tracking id configured by an administrator. See the example in Querying.cs, block2, how the table ID corresponds to the current site is retrieved.
The data tracked for users visiting the site can be tracked using a Google Analytics service proxy. The Google Analytics module provides a wrapper for this class which caches the results for a specific query. See the example in Querying.cs, block3, how the query helper can be used to issue a data query.
See the example in Querying.cs, block4, how the code gets the query results for page views over time ands binds to a grid view.
See the example in Querying.cs, block5, for some more example queries.
This document describes how to track custom actions and transactions using the Google Analytics module for EPiServer.
The module adds a tracking script which tracks page views and built-in events. The module can be disabled using plug-in settings in admin mode. The script is added using Page.ClientScript. This requires a form runat="server" on the page. If no form exist on the page the script can be added manually.
Events can be tracked and displayed in the gadgets. To track events execute the following extension method during the page life cycle.
See the example in Tracking.cs, block1.
Commercial transactions can be tracked by executing an extension method during the page life cycle.
See the example in Tracking.cs, block2.
The EPiServer Commerce extension simplifies tracking a purchase order.
See the example in Tracking.cs, block3.
Sometimes it is more convenient to track events on the client. Example:
// create a function that uses the event tracking API
function trackEventWithGoogle(){
if (_gaq) { _gaq.push(['_trackEvent', 'Example', 'Clicked', 'Tracking example clicked', 1]);
}
}
// execute the function when clicking on "button1" button1.onclick = trackEventWithGoogle;
In situations when there is not form runat="server" or when using MVC the tracking script that would be rendered by the Google Analytics module can be generated programmatically.
See the example in Tracking.cs, block4.
To render the tracking script on ASP.NET MVC, use the following HTML helper:
Html.AnalyticsTrackingScript(currentPage)
A checkout process typically ends with a thank you page. This is a good place to track purchases with Google Analytics.
Do not forget to enable e-commerce tracking at http://google.com/analytics/ below admin/profiles/profile settings/.
HOW TO integrate e-commerce tracking on EPiServer Commerce Enoteca sample site:
<episerver.shell>
<publicModules>
<add name="EPiServer.GoogleAnalytics">
<assemblies>
<add assembly="EPiServer.GoogleAnalytics.Commerce" /> </assemblies>
</add>
</publicModules>
</episerver.shell>
<handlers>
<clear />
<!-- This registers a http handler that provides tracking information about an order identified by tracking number and the user session. The tracking information can be used by by a client side javascript to track purchaes with google analytics -->
<add name="orderTracking"
path="OrderTracking.ashx"
verb="GET"
type="EPiServer.GoogleAnalytics.Commerce.OrderTrackingHandler, EPiServer.GoogleAnalytics.Commerce" />...
<script type="text/javascript">
jQuery(function ($) {
// This event is triggered by the checkout scripts, from it we can read a tracking number
// used to find the appropriate transaction and generate purchase information to track. $("body").bind("checkout.onSavedData", function (e, data) {
// OrderTracking.ashx is a http handler configured in web.config
if (data.data && data.data.isSuccess && data.data.OrderNumber) {
// Ask the server to generate tracking information from the purchase
$.getJSON("OrderTracking.ashx?trackingNumber=" + data.data.OrderNumber, function (data) {
// The result contains an isSuccess which is true when a purchase order was found
if (!data.isSuccess || typeof _gaq === "undefined") { return;
}
// The result contains a list of tracking arrays that can be pushed directly to the google tracking API data.transaction.forEach(function (item) {
_gaq.push(item);
});
// Sends the tracking information to google _gaq.push(['_trackTrans']);
});
}
});
});
</script>
HOW TO integrate tracking on a site that redirects to a thank you page after purchase:
// The order number needs to be available on the thank you page, in this case using a query string parameter string trackingNumber = Request["trackingNumber"];
// Finds the purchase order with the given order number var order = Mediachase.Commerce.Orders.OrderContext.Current.GetPurchaseOrders(Mediachase.Commerce.Customers.CustomerContext.Current.CurrentContactId).FirstOrDefault(po => po.TrackingNumber == trackingNumber);
// Registers the order to be tracked by the google analytics tracking script added by the module.Context.AddAnalyticsTransaction(order);
Last updated: July 2, 2012