Global Placeholder Settings – Why a unique Placeholder Key is important

Ever got a warning on saving a Global PlaceholderSetting with the same Placeholder Key?

Sitecore-Placeholder-Setting

Introduction:

We had discussed about Global and Data-Template specific Placeholder Settings in the following articles:

https://varunvns.wordpress.com/2014/07/03/placeholder-settings-empower-your-page-editor-users/

https://varunvns.wordpress.com/2014/07/07/placeholder-settings-empower-your-page-editor-users-part-2/

Here, lets discuss a challenge which we might face, when configuring a Global Placeholder Setting and how to overcome that.

Challenge:

As we know, a Global Placeholder Setting, is a one with a Placeholder key assigned to it. So whenever a PageEditor user want to add a component to a page, they can go to the PageEditor aka Experience Editor and go to any particular Placeholder and add the configured component for that particular Placeholder, with help of Placeholder Setting. I am sure you might have referred to this article mentioned above, but in case you missed it, check it out for  details.

Now, whenever we have two Global Placeholder Settings with the same key, Sitecore warns us right at the time when we set the key to be the same but if we ignore it, this is what happens. Sitecore always applies the first PlaceholderSetting out of the two in the list with a given placeholder key.

Example:

I have installed a Sitecore solution which comes with a Global placeholder setting called content – /sitecore/layout/Placeholder Settings/content with the Placeholder Key as “content”. This is how it looks:

Sitecore-Placeholder-Settting

As we see above, the Allowed controls set in the setting is Sample Rendering.

Now, I create a new Placeholder Setting called My content, with the same Placeholder key as “content”. I will create it in a folder called A, so that it stays above the content Placeholder Setting, we just saw.

 The Allowed controls, as we see above are Sample Sublayout and Sample Datasource Sublayout.

Now, lets go to the Page Editor and click on the components button, to check where all can we add a new component.

Sitecore-Add-a-New-Component

 

As we see, there is availability of adding new components to the content Placeholder key — Lets click on Add to here button.

Sitecore-My-Placeholder-components

 

If we check, these are the components of My Content Placeholder Setting. Now, let me rename the folder A to Z — so that it moves below the content (/sitecore/layout/Placeholder Settings/content) Placeholder Setting. Now, lets go to the Page Editor again, click the Add a New component button and click on Add to Here of content Placeholder.

Sitecore-content-Placeholder-Setting-after-Folder-rename

And, what we find is, the Placeholder Setting  content (/sitecore/layout/Placeholder Settings/content) is applied.

Why is this happening?

Maybe because Sitecore considers the first Global Placeholder Setting with a given Placeholder Key and applies it to our website.

The biggest question that arises in our mind is When we might face such a case?

Well, such a case will generally not occur in a single-website instance of Sitecore. It can mainly occur in a multi-site Sitecore solution, say we have a Placeholder Setting called “Header-Setting” with the assigned Placeholder key as “header”  for more than one sites in the same Sitecore solution. In that case, Sitecore will always consider the 1st PlaceholderSetting for a Placeholder Key and not the site specific Placeholder Setting.

Solution:

Firstly, its always good to have Placeholder Settings, as we know it empowers the Page Editor users. So lets not think of removing it from our Sitecore solution.

Instead, lets create Global Placeholder Settings with a site-specific Placeholder Key, so that it doesn’t clash/collide with other Placeholder Setting. Next, if we have Global Placeholder Settings, and we link them with the content items i.e. ideally in the Standard values of templates, for all those items where that particular Placeholder Key might appear, we will never face such an issue. Or else, lets always create a Template-specific Placeholder Setting rather than a Global Placeholder Setting.

Lastly, Sitecore is an awesome solution and it even gives us great validation messages. So we need to be careful enough to read and understand them and work accordingly. If we do that, we will never ever face this issue!

Happy Sitecoring!

Sitecore recognized Author’s Endeavor and Bestowed Sitecore MVP Award!

Dear Sitecore Family,

I am sure you will be happy to know, that your own Sitecore Endeavor Blog Author, who had started the blog with his vision or endeavor of sharing as much information on Sitecore with the family, has been recognized by Sitecore and he is awarded Sitecore Most Valued Professional Technology Award for 2015.

Sitecore-MVP-2015

Now in it’s nineth year, Sitecore’s MVP program recognizes individual technology and digital strategy advocates who share their Sitecore passion and expertise to offer positive customer experiences that drive business results. The Sitecore Technology MVP Award recognizes the most active Sitecore experts from around the world who participate in online and offline communities to share their knowledge with other Sitecore partners and customers.

“We are grateful for the leadership, expertise and ongoing contributions that Varun Shringarpure has made to the Sitecore community,” said Lars Fløe Nielsen, Co-Founder and senior vice president, technical marketing, Sitecore. “ Varun Shringarpure has demonstrated mastery of our technology and exemplifies the spirit of Sitecore.”

Sitecore’s experience platform combines web content management, omni-channel digital delivery, customer insight and engagement, and strategic digital marketing tools into a single, unified platform. The platform is incredibly easy to use, capturing every minute interaction – and intention – that customers and prospects have with a brand, both on a website and across other digital channels. The end-to-end experience technology works behinds the scenes to deliver content targeted to individual customers, so that they engage in relevant brand experiences that earn loyalty and achieve results.

I would like to take this opportunity to thank all of them without whom I won’t have achieved my Endeavor. Firstly, its thanks to God, who helped me in my tough times and helped me concentrate on my goal to share. Next, is my family, who never complained my unavailability on a number of occasions when I was busy focusing on my Endeavor. Next, its a Big thanks to my Mentors, Kiran Patil and Hardeep Bhamra, without whom, this would never have been possible, they are a very important part of my Sitecore Journey and deserve all the credit. Thanks to the Sitecore Development Team who built such an awesome platform for all of us to work and are continuously working and innovating it with cutting edge technologies to make and stay a Global Leader. Thanks to Sitecore Support Team, in our tough times when we are in a situation and unable to find a way they come to our rescue and help us find a way. And last, but not the least its A BIG BIG thanks to all of you! Yes You, My Dear Sitecore Family! Because, you read the blog articles, liked them, recommended them to others, shared them with others you sent me messages and comments which inspired me write more and more on. It really feels great to be a part of the elite group, but at the same time, I believe its a greater responsibility given to me by Sitecore. And I promise you, this is not the end, this is just the Start of Something New!!

Again, as its my Birthday tomorrow, I consider it as my Birthday present! :)

Congratulations to all the Sitecore MVPs!

Happy Sitecoring and Happy Sharing, Because Sharing is Caring!

2014 in review

The WordPress.com stats helper monkeys prepared a 2014 annual report for this blog.

Here’s an excerpt:

The concert hall at the Sydney Opera House holds 2,700 people. This blog was viewed about 17,000 times in 2014. If it were a concert at Sydney Opera House, it would take about 6 sold-out performances for that many people to see it.

Click here to see the complete report.

Sitecore Version Upgrade – Whitepaper

My dear Sitecore Family,

I was working on this document since a very long time, changed small things multiple times, added new sections almost every time and updated the flow-charts to make them as much easy to understand as possible.

This is a Whitepaper on Sitecore Version Upgrade – a whole and sole document that can help all of us to understand what Sitecore Version Upgrade is and why it is required and how can we do it. It covers a number of questions that I have found different developers asking each other either in a meeting or on Forums as well as a number of learnings that our team gained, while upgrading our Sitecore Solution.

 

So my dear friends, here’s the Document for all of you! Yes YOU!! — The Sitecore Version Upgrade Whitepaper

 

 

One small request to each and every reader who refers to this document, to kindly give your honest review and let me know if there are any mistakes.  Also, it would be nice to improve this document further, by adding some more learnings or scenarios that any of you might like to share! I would be happy to discuss it out with you and would incorporate it in this document.

Happy Sitecoring! :)

Sitecore MVC – Getting Started

Dear Sitecore Family,

A few months back, I had started with Sitecore MVC. A couple of weeks back, I and my collegue Bhavesh Maniya, took a presentation for our internal team on “Getting Started with Sitecore MVC”.

So I thought, why not share here, with the whole Sitecore Community, it could be helpful many.

So here it goes!

 

Coming Soon:

  • A Demo Site on Sitecore MVC that I made while learning Sitecore MVC
  • My Learnings of designing and developing a Sitecore Project using Sitecore MVC in an effective way!

Hope this helps!

Happy Sitecore MVCing! :)

Tracking PDF Downloads in Google Analytics in a Sitecore Website

Hello my dear Sitecore Family,

Firstly, Thank you so much for your response on my last post — how to Configure Google Analytics for a Sitecore Website via Twitter and Email. It inspired my to write more on the connecting yet quite useful topic. In case you missed the last post, check it out here: https://varunvns.wordpress.com/2014/09/22/configuring-google-analytics-for-a-sitecore-website/

Today, lets look at how to track PDF downloads in Google Analytics.

  • Basic understanding of Tracking PDF Downloads in Google Analytics:

There are two ways in which we can track them:

  1. As a Virtual PageView
  2. As an Event.

But logically, I feel that tracking a PDF download as an Event is better – still choice is yours, and we will also discuss how to track it as a virtual PageView if required.

How can we configure this?

What we need to do is, we need to put the Google Tracking code in the link of PDF, so that whenever it is clicked, it sends the required information to Google. This information is inturn available to us via Google Analytics.

A sample given by Google for the same is as follows:


<a href="#" onClick="_gaq.push(['_trackEvent', 'Videos', 'Play', 'Baby\'s First Birthday']);">Play</a>

  • Basics of Configuring and Tracking PDF Downloads in Google Analytics:

We will first discuss how to track PDF Downloads as events in Google Analytics. By the end of the post, we will also discuss a few changes, so that we can configure PDF downloads as a Virtual Pageview. As with the case of Configuring Google Analytics, we can do this in one of the two ways – either using Classic Google Analytics (ga.js) or using Universal Google Analytics (analytics.js)

Still, we need to make sure that Google has already mentioned, to upgrade to Universal Analytics from Classic Analytics. So its good to use that.

Add-Universal-Analytics

 

Pre-requisites:

  1. Google Analytics must be configured in our website.
  2. Media.RequestExtension in our web.config is not set to ashx (because, in that case, your PDF will have an extension of .ashx in the HTML and if so, then how can we append the Google tracking code to it. (http://sitecoreblog.patelyogesh.in/2013/09/sitecore-media-url-remove-ashx-extension.html)

Events Classic Google Analytics (ga.js)

There is a nice post written by Mr. Mortaza Kamal Nourestani, to track PDF Downloads in Sitecore for Classic Google Analytics – http://nourestani.wordpress.com/2012/06/12/how-to-track-downloads-in-google-analytics/

So its a great thanks to him for this.

Events Universal Analytics (analytics.js)

A small piece of code written by me, inspired by Mr. Mortaza.


<script type="text/javascript">
if (typeof jQuery != 'undefined') {
jQuery(document).ready(function ($) {
var filetypes = /\.(pdf)$/i;
var baseHref = '';
if (jQuery('base').attr('href') != undefined) baseHref = jQuery('base').attr('href');
jQuery('a').each(function () {

var href = jQuery(this).attr('href');
if (href) {

if (href.indexOf('?') != '-1') {
href = href.substring(0, href.indexOf('?'));
}
if (href.match(filetypes)) {
jQuery(this).click(function () {
//var ga = ga || [];
var extension = String((/[.]/.exec(href)) ? /[^.]+$/.exec(href) : undefined);
var filePath = String(href);
var filename = filePath.replace(/^.*[\\\/]/, '')
ga('send', 'event', 'PDF-Downloads', filename, document.URL);
if (jQuery(this).attr('target') != undefined && jQuery(this).attr('target').toLowerCase() != '_blank') {
setTimeout(function () {
location.href = baseHref + href;
}, 200);
return false;
}
});
}
}
});
});
}
</script>

Both the above code snippets, do the same thing, — find the extension “PDF” and append the Google Analytics Event Tracker code into it. Thus, whenever the PDF link is clicked — the PDF is opened or downloaded — information is gathered by Google and shown to us.

 

Basic Steps:

  1. Make sure that Google Analytics is Configured for the current Sitecore Site. In case it isn’t follow this article to configure it – https://varunvns.wordpress.com/2014/09/22/configuring-google-analytics-for-a-sitecore-website/
  2. Create a Sublayout in our Sitecore Solution.
  3. Copy one of the above given code (preferably Universal Analytics) to the Sublayout.
  4. Statically bind the Sublayout to all (one or more main layouts of the Sitecore Site. (https://varunvns.wordpress.com/2014/07/03/sitecore-beginner-static-and-dynamic-binding/)
  5. Upload a test PDF and link it to one of your Sitecore content item. (I haven’t checked, what would happen if we have upload as ashx you can check and definitely let me know. But better check the pre-requisite above.)
  6. Open any page with a PDF link.
  7. When the page load completes, view the Page Source.
  8. Search for the PDF link (anchor tag using which the PDF is linked)

These are the simple basic steps, which would make it work just fine. They will be displayed in a Category called PDF-Downloads, as that’s what we have mentioned in the code above.

Now, lets consider a case, wherein we have different PDFs for different use and want to configure them category wise in Google Analytics. But before that, lets first understand something.

PDF-Downloads-GA-Understanding

So now, if we want to categorize the PDFs further based on need or Client requirement and as we said in the beginning of the post, if we want to configure it as a virtual PageView instead of Event Tracking on the fly, we can do that too. Lets see how.

Advanced Steps:

  1. Make a section in Global Sublayouts (which is shared between all the sites in our solution) and lets create a Sublayout GA-PDFDownloads.
  2. Copy the  Universal Analytics code given above with just one line of change — adding Properties instead of Hit Type and Category as in the screenshot below:PDF-Downloads-Sublayout-code
  3. Statically bind the Sublayout to all (one or more main layouts of the Sitecore Site. (https://varunvns.wordpress.com/2014/07/03/sitecore-beginner-static-and-dynamic-binding/)
  4. In the Template of HomePage of the website or in a Global Settings Section template of a site, create two fields to store Data about Google Analytics PDF Downloads.PDF-Downloads-Template-Sections
  5. Add the field values in the items. PDF-Downloads-Item-Values6.  In the code behind of the Sublayout, initialize the Properties and in the Page_Load function write a code to fetch their values as below:PDF-Downloads-Sublayout-code-behind

 

Want the code? Well, here it is!

<script type="text/javascript">
 if (typeof jQuery != 'undefined') {
 jQuery(document).ready(function ($) {
 var filetypes = /\.(pdf)$/i;
 var baseHref = '';
 if (jQuery('base').attr('href') != undefined) baseHref = jQuery('base').attr('href');
 jQuery('a').each(function () {

 var href = jQuery(this).attr('href');
 if (href) {

 if (href.indexOf('?') != '-1') {
 href = href.substring(0, href.indexOf('?'));
 }
 if (href.match(filetypes)) {
 jQuery(this).click(function () {
 //var ga = ga || [];
 var extension = String((/[.]/.exec(href)) ? /[^.]+$/.exec(href) : undefined);
 var filePath = String(href);
 var filename = filePath.replace(/^.*[\\\/]/, '')
 //ga('send', 'event', 'PDF-Downloads', filename, document.URL);

 ga('send', '<%= GoogleAnalyticsHitType %>', '<%= GoogleAnalyticsCategory %>', filename, document.URL);

 if (jQuery(this).attr('target') != undefined && jQuery(this).attr('target').toLowerCase() != '_blank') {
 setTimeout(function () {
 location.href = baseHref + href;
 }, 200);
 return false;
 }
 });
 }
 }
 });
 });
 }
</script>
public string GoogleAnalyticsHitType { get; set; }
public string GoogleAnalyticsCategory { get; set; }

protected void Page_Load(object sender, EventArgs e)
{
Item SettingsItem = Sitecore.Context.Database.GetItem(Sitecore.Context.Site.RootPath + Sitecore.Context.Site.StartItem + "/Settings");

//Google Analytics Tracking can either be Event Tracking or Virtual PageView Tracking - better is Event Tracking
//If "Google Analytics Track PDF Downloads" field is empty in the Settings Item, then consider it as Event Tracking by default
if (SettingsItem != null && !String.IsNullOrEmpty(SettingsItem["Google Analytics Track PDF Downloads"]))
GoogleAnalyticsHitType = SettingsItem["Google Analytics Track PDF Downloads"];
else
GoogleAnalyticsHitType = "event";

//If "Google Analytics PDF Category" field is empty in the Settings Item, then consider "PDF-Downloads" as the category by default
if (SettingsItem != null && !String.IsNullOrEmpty(SettingsItem["Google Analytics PDF Category"]))
GoogleAnalyticsCategory = SettingsItem["Google Analytics PDF Category"];
else
GoogleAnalyticsCategory = "PDF-Downloads";
}

Happy Tracking PDF Downloads in Google Analytics! :)