Daily Tip: Add icons to Fieldsections

To make thinks easier for the business-users you can use Icons for templates. This is a great way to make the business-user recognize the different types of content they can create. But did you know you can also use icons for your Fieldsections?

Set Icon with the webinterface

You can set icons for Fieldsections the same way as you do for your templates. Just open the content editor, expand a template and underneath a template you will find all your FieldSections. Select a field section and set the icon!`

For example. Let’s say we have a template called Sample Item with a Fieldsection Page Title and Text.
If you expand Sample Item Template you can see that there is a Item named Page Title and Text this is the Template Section defined in the Template builder.

Sitecore Template Icon

Select the Page Title and Text item and assign a icon (Configure –> Appearance –> Icon). That’s it. Now create a new Item based on the template and see the result.

Sitecore fieldtype item content editor

Try doing this on your templates. It’s so easy and it will make the Content Editor more attractive for your business-user. Feel free to add comments of questions below.

Update: Set Icon with Sitecore Rocks

You can also set the Template Section Icon with Sitecore Rocks. Expand the template in the Sitecore Explorer and right click the Template Section. Go to Tasks, Set Icon and select the Icon.  (Thanks to @kayeeNL for his Tweet about setting the icon with Rocks)

image

If you want more information about Sitecore Rocks please watch the (Dutch) webinar I gave about Sitecore Rocks.

Step 3: Create the outgoing link report

This article is part 3 of Sitecore How To: Track Exteral links with DMS series. Before starting with this step you need to be finished with Step 2. Otherwise you don’t have any report data.

Show the outgoing links in a report

The easiest way to generate a report is find a report that matches your needs, copy the report and change the datasource and layout. For this POC the Slow Pages report matches 80% of my requirements, so let’s use the Slow Pages report as a base for our new report.

Download the External Links per Page.mrt Report

You can download the External Links per Page report. Unpack the zip file and save .mrt the file in the folder /sitecore/shell/Applications/AnalyticsReports.

This report is a customized version of the slow pages report. For more information about report designing you can read the Report Designer Cookbook

Copy the Slow Pages Report SQL Query Item

Duplicate the slow pages Report SQL Query item (/sitecore/system/Settings/Analytics/Reports SQL Queries/Slow Pages) and name the Item External Links per Page.

Delete the SQL query in the SQL server field and add the following SQL query.



select    top 100
Pages.Url,
PageEvents.Data as Link,
COUNT(*) as Clicks
from
Pages,
PageEvents,
Visits,
PageEventDefinitions
where
Pages.VisitId = Visits.VisitId
AND Pages.PageId = PageEvents.PageId
AND PageEventDefinitions.PageEventDefinitionId = PageEvents.PageEventDefinitionId
AND PageEventDefinitions.Name = 'External Link'
AND Visits.StartDateTime BETWEEN @StartDate AND @EndDate
group by
Pages.Url, PageEvents.Data
order by
Clicks desc


This query will return all outgoing clicks from every page.

Copy the Slow Pages Report Item

Open the content editor and duplicate the Slow Pages Report item located at: /sitecore/system/Settings/Analytics/Reports/Reports/Site Health/Slow Pages

Name the duplicated report External Links per Page.

In the External Links per Page item change the Filename to External Links per Page.mrt and change the Report Title field.

In the Queries section. For Failure select the External Links per Page Report SQL Query item.

 

Sitecore DMS Queries
Note: You might want to rename the datasource name Failure to something like Datasource. If you do this you need to do a search and replace within the .mrt file.

Test you report

Login to the Sitecore Desktop and open the Engagement Analytics. Underneath the Site Health node you will find the External Links per Page report.

 


In this report we can see that we generated three clicks from our products page to Google.nl and two clicks from our homepage to test.nl.

This report is only a example. You can create all kind of reports all based on the event table in the Analytics Database.

Webinar: Sitecore and Continuous Integration

webinar sitecore continuous integration

Today Lucas Bol gave the first Dutch Sitecore guest Webinar. The subject of this webinar was continuous integration with Sitecore based on open source products. The video is in Dutch and posted below.

[youtube]http://www.youtube.com/watch?v=Nd__rUJtLq0[/youtube]

In the next few days Lucas will post his documentation and explanation of the webinar in English. Follow us on Twitter @new_guid or subscribe to our RSS feed if you want an update when this is posted.

 

Step 2-1: Track all external links with a custom processor

This article is part of Sitecore How To: Track Exteral links with DMS series. Before starting with this step you need to be finished with Step 1: Save outgoing click to the DMS analytics database.

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.

Sitecore custom processor

The Render Field Processor Template will generate two files for you; the ExternalUrlReWriterProcessor.cs and a  ExternalUrlReWriterProcessor.config.

 

Custom sitecore config processor

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.


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;

}
}


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.

Step 1: Save outgoing click to the DMS Analytics database

This step is the first of the series: How to track External Links with Sitecore DMS. In this step we are going to create a page (link.aspx) that will register the outgoing traffic into the Sitecore Analytics database and redirects the visitor to the external website.

Save the outgoing click information to the Analytics database

Create the custom page event

Open the content editor, go to /sitecore/system/Settings/Analytics/Page Events and create a Page event called External Link.

Under the Options field section select the IsSystem checkbox

 

We refer to the name of this Page Event Item when saving the outgoing link to the Analytics database.

Create the sublayout

Create a sublayout called LogExternalLink. In the Page_Load event add the code.



protected void Page_Load(object sender, EventArgs e)
{
if (Tracker.IsActive)
{
bool trackClick = true;
//Check if outgoing traffic is generated within a visit of the site
if (Tracker.CurrentVisit.PreviousPage == null)
{
//The visit is a direct visit or from another website, don't add this link to the analytics db.
//OPTIONAL; Log these links based on referrer url.
trackClick = false;
}

//Get linkUrl from querystring
string externalUrl = Request.QueryString["url"];

//Check if link is set
if (!string.IsNullOrEmpty(externalUrl))
{
if (trackClick)
{
//Create PageEvent, the name must match Page Event item in Sitecore
PageEventData data = new PageEventData("External Link");
//Set PageEvent data
data.Text = string.Format("Outgoing traffic to: {0}", externalUrl); ;
data.DataKey = externalUrl;
data.Data = externalUrl;

//Add the event to the previouspage; that's where the link is clicked
Tracker.CurrentVisit.PreviousPage.Register(data);
Tracker.Submit();
}
//Redirect visitor
Response.Redirect(externalUrl);
}
}

//Something not right here, send them back to the homepage
//TODO: Log Error or Warning
Response.Redirect("/");
}


Based on your businesscase you could choose to create a handler. A handler will have less overhead.  If you create a Sublayout you could create a screen telling the visitor that there are leaving the website (for example like Facebook does).

Now create an item link underneath the website root and place the LogExternalLink sublayout that we just created on this item. This item will be the link.aspx page. All external links will be redirected and processed trough this page.

Test if it works

At this point we cannot test this part of the solution. Testing this solution is only possible if the tracking page (link.aspx) is referred from the website. We don’t want to  track URLs that are triggered from a direct request.

We will test this part of the solution after Step 2  of the series: How to track External Links with Sitecore DMS.

 

Sitecore How To: Track Exteral links with DMS

In this How To I’ll show you how to extend Sitecore to track outgoing links trough the Sitecore Digital Marketing System (DMS).

First of we start with creating a sublayout that saves the outgoing link clicks to the Analytics database. Next step is creating a solution for tracking the outgoing link. There are multiple solutions of tracking external links but in this series we are creating the following two solutions; one that tracks all outgoing links automatically (step 2.1) and the other solution where it´s possible to enable tracking for-each outgoing link (step 2.2)And off-course we finish with  report that will show you the most clicked outgoing links.

This how to is part of the series: How to track External Links with Sitecore DMS and contains the following steps:

  • Step 1: Save outgoing click to the DMS analytics database (status: finished, published)
  • Step 2: Two solutions for outgoing link tracking
    • Step 2.1: Measure alloutgoing links with a custom processor  (status: finished, published)
    • Step 2.2: Measure specific outgoing links by creating a custom external link fieldtype
      • Step 2.2.1: Creating the custom external link fieldtype (status: review, publishdate: 17/05/2012)
      • Step 2.2.2: Creating pageeditor support for the custom external link fieldtype (status: coding)
      • Step 2.2.2: Tracking the external links that need to be tracked (status: on hold)
  • Step 3: Creating the outgoing link report  (status: finished, published) 
And off-course all publishdates are subjected to changes ;=)

Want to receive a reminder when a new article is publish subscribe to the RSS feed, maillinglist (in the right sidebar) or follow us on @new_guid

Feel free to ask your questions in the comment form below.