This article is based on a Dutch webinar that I presented august 2012 and will refer to the video recording, slides, the How to documentation and used resources.
With Ghostery you can check cookie and tracking information of a website. This tool can help you to identify cookies and tracking technologies that your website is using. This information can be helpful to determine the strategy for your website to be compliant with the new EU cookie law.
Ghostery is a Google Chrome plugin, after the installation you can configure the default settings for Ghostery.
Now if I open the CNN website in Chrome, I´ll get the following information.
This information windows shows that CNN site is using 7 tracking codes and/or cookies. So this is interesting… But there is more you can do, you can also get information about all the different tracking codes, let’s say that I want to know more about NetRatings SiteCensus. To do this I can click the Ghost (with the 7) next to the address bar and click on the more info link next to NetRating SiteCensus.
A new tab window will open the website of Ghostery with detailed information about the tracking script. Now I can tell you what NetRating Sitecensus does:
“SiteCensus is a browser-based audience measurement tool that provides in-depth tracking and analysis of your Web site users, site performance and other critical measurement data. Examine your site performance, usage trends, content and product placement, visitor loyalty, search engine performance and visitor behavior.”
This tool can do much more than this, so go download Ghostery and check-out which tracking technology your site is using.
For this solution I want to measure all the outgoing link using the Analytics Database of Sitecore Digital Marketing System (DMS). Based on this data I want to create a report in the Sitecore Engagement Analytics that will show all outgoing clicks by page. I want to create a solution that rewrites all external links within rich-text fields and General Link fields. With this solution all external links on an existing website will be automatically rewritten and measured.
In this article I will create a solution for measuring outgoing links in the following steps:
Create a processor to rewrite all external links on the website.
Let get started!
Create the processor for rewriting external links
For the rewriting of the external links we are creating a Render Field Processor. This processor will fire for every field that is rendered. During this process we will rewrite the URL.
The easiest way to create a new processor is with the Visual Studio 2010 plugin Sitecore Rocks. One of the many things Sitecore Rocks does is creating Visual Studio Templates. These templates will help you extending Sitecore. Open your solution in VS2010 and add a new item. In the dialog window go to Sitecore –> Pipelines en selecteer Render Field Processor. Name the processor ExternalUrlReWriterProcessor.cs and click Add.
The Render Field Processor Template will generate two files for you; the ExternalUrlReWriterProcessor.cs and a ExternalUrlReWriterProcessor.config.
Modify the ExternalUrlReWriterProcessor class that all external URLs are rewritten to out /link.aspx page that we are going to create next. Below is my POC code. Please take notice of the comments and the TODO comments.
[code language=”csharp”]
public class ExternalUrlReWriterProcessor
{
public void Process([NotNull] RenderFieldArgs args)
{
// Do not modify output if the field is not a rich text field or general link
// or if the page is in page editor mode
if ((args.FieldTypeKey != “rich text” && args.FieldTypeKey != “general link”) ||
String.IsNullOrEmpty(args.FieldValue) ||
Sitecore.Context.PageMode.IsPageEditorEditing)
{
return;
}
//Check if URL is external link
if (args.FieldTypeKey == “general link”)
{
Sitecore.Data.Fields.LinkField linkField = args.GetField();
//Don’t change the link if it’s not a external link
if (linkField.LinkType != “external”)
return;
}
string fieldValue = args.Result.FirstPart;
string changedUrl = Regex.Replace(fieldValue, @”href=””(.*?)”””, delegate(Match match)
{
//Regex definition to check if URL contains HTTP or HTTPS (so it’s an external link)
Regex rgxExternal = new Regex(@”Regex rgxExternal = new Regex(@”(((http(s?))\://){1}\S+)”);”);
string orriginalUrl = match.Groups[1].Value.ToString();
if (rgxExternal.IsMatch(orriginalUrl))
{
//Rewrite the url to the redirect item
//TODO: Make the path configurable
return @”href=””/link.aspx?url=” + orriginalUrl + @””””;
}
return match.Value;
}, RegexOptions.Compiled);
args.Result.FirstPart = changedUrl;
}
}
[/code]
If you check your website all external links will be rewritten to /link.aspx?url=[EXTERNAL LINK]. Now let’s create the links.aspx and save the outgoing link information to the DMS Analytics database.
Test if it works
You can test if the solution is working on your website by testing the following functionalities
Action
Expected result
Create a internal link in a rich-text field
The link is not rewritten.
Create a external link in a rich-text field
The link is rewritten to /link.aspx?url=[THE LINK]
Create a internal link in a general link field
The link is not rewritten.
Create a external link in a general link field
The link is rewritten to /link.aspx?url=[THE LINK]
Click a external URL
The visitor is redirected to the external website.