Sitecore-how to create custom personalization rule

Personalization is the method for displaying targeted and relevant content to  website visitors based on different characteristics  like location, age, visits, etc.. There are several rules available out of the box in Sitecore which can be leveraged to personalize web pages.

Personalization-2

It is also possible that we have to build and create custom personalization rules to support certain business requirements, Sitecore architecture is flexible enough to support this scenario and can be extended to implement custom rules based on the requirement.

As part of this post, i would like to show how we can extend and build custom personalization rules, we will take an example of creating a custom rule where based on querystring parameter value how we can display different content to our site visitors.

Let’s take an example where we would like to show website visitor component-1 when user search for keyword=”content” and show component-2 when user search for keyword “management”.

Here are the steps to follow:

Step 1- First step is to create a new tag for our Custom rule under “/sitecore/system/Settings/Rules/Definitions/Tags” based on template- “/sitecore/templates/System/Rules/Taxonomy/Tag”

Sitecore-Tag

Step 2- Next- create custom Element and personalization condition under “/sitecore/system/Settings/Rules/Definitions/Elements”

Personalized-Rules

As part of personalization condition there are two fields to populate:

  • Text
    • It shows text that would be presented to content editors when using this condition with Rules Engine, this is what we have used in this example-
    • Where the querystring parameter search has a value that [operatorid,StringOperator,,compares to] [querystringvalue,,,Value]

    • Everything under square brackets []  would be replaced by Rules Enging as selectors.
  • Type
    • Type specifies fully qualified class and assembly names where we want to write/perform the business rule for the custom personalization condition.

Step 3- Next step is to assign custom tag which we created in step#1 to default element tag definition.

Element-tag

Step 4- Next- we would need to add this tag to conditional rendering such that this new rule is available in the rule editor for content editors to personalize the components, please make sure to name your tags and custom elements self explanatory as much as possible for better content editors experience.

conditional-rendering

Step 5- Once all the above changes are made content/business editors can configure this rule to personalize the components from experience editor or content editor from presentation->Personalize section.

rule-editor

In the below code snippet we can see that we have created a class SCCustomRule which inherits StringOperatorCondition class and override Execute(T ruleContext) method -as we are trying to compare the querystring value of what has been configured in the rule editor and what has been actually entered by end user.

If the parameter values matches the rule is satisfied and the personalized component will be displayed else it would display the default component.

custom-personalization-snippet

Similarly we can create other custom rules to show more relevant and targeted content to our end users based on how they have interacted and what details they have stored in the system (internal/external)

Hope this helps.

Happy learning 🙂

Why Sitecore-from my view

Different content management systems (CMSs) are available for creating and managing websites, but choosing the right CMS is always a big challenge and depends on several factors, Web content management system (WCMs) are not just a tool for creating pages now, it has gone beyond it and business now count on it to perform and manage many other functions.

Recently i was asked to list down why Sitecore is an ideal choice as content management system, you can find articles advocating for Sitecore and explaining the features which makes it an optimal choice as a content management system, here i want to share my view on why Sitecore is the best choice.

Before we start, just to mention that Sitecore has been awarded as a leader in Gartner’s assessment of the strengths and cautions of 18 web content management vendors for 9th year in the row. sourcehttps://www.sitecore.com/resources/index/analyst-reports/gartner-magic-quadrant-for-web-content-management

Sitecore-AEM

Here are some of the features/advantages of Sitecore from my perspective which makes it a product of “one stop shop” for all.

  1. Friendly Interface- Sitecore user interface was made keeping usability in mind.With its intuitive interface, even non-technical users can make changes and updates on the fly.
  2. Multisite development- Sitecore’s feature of Multisite development enables development team to work on multiple websites at the same time, this includes microsites/intranets applications and etc.
  3. Integration- Sitecore architecture is based on extensibility which supports integration with third party systems,you can integrate some of the third party systems like Salesforce/Active Directory/Brightcove connectors and etc. in your Sitecore solution smoothly.
  4. Multilingual Sites and translations– Sitecore helps your business to reach out to global or local market by translating the contents into regional languages by means of different connectors which can use to translate the content into different languages.you can translate the content manually or make use of connectors- choice is yours.
  5. Analytics– Experience Analytics is built in which gives business editors/users an insight of customer behavior and journey so that we can recognize patterns and update the content and personalize to present more relevant contents to end users.
  6. Devices-  System can target the content based on devices which has been used to request particular page.
  7. Scalability–  You can scale your application to any level you want right from content management servers to your experience database(xDB) and content delivery servers. Sitecore provides a system to make sure your data is safe and protected. We can setup multiple CD servers to load balance the traffic and making sure the nearest server is being used to serve the user request to improve the performance.
  8. Extensive Support from Sitecore– You are always in safe hand while working in Sitecore, for any issues and problems Sitecore has different channels available where you can raise your concerns and queries. Some of the tools which you can use are as follows:
    1. support.sitecore.net
    2. Sitecore slack
    3. Sitecore stackoverflow
    4. dev.sitecore.net
  9. Deploy on  Azure- We can deploy Sitecore on Azure using modals like PAAS and IAAS, and can leverage other cloud features to best serve the application and users.
  10. SXA (Sitecore Experience Accelerator)– SXA Speeds up the delivery while running different work steams in parallel.
    1. Web development teams use Sitecore Experience Accelerator (SXA) to speed up the production of websites and to reuse components, layouts, and templates across a variety of sites.
    2. SXA separates structure from design, so front-end designers, creative designers, content authors, and developers can work in parallel and you can deploy and maintain multiple sites quickly and cost effectively
    3. Once a basic user experience plan is in place, everyone can get started on the platform
    4. For example: the content author can start entering the content in the wireframe environment, while the front-end developer works on the theme, and the developer sets up the data templates.
  11. Personalization-
    1. Personalization is all about presenting relevant content to end users based on several factors like browsing history, campaigns, goals, visits and etc.
    2. Sitecore comes handy with several out of the personalization rules which you can use out of the box.
    3. We can also built custom rules to create and show specific component variant which can be displayed when custom personalization rule/condition is met.
  12. Marketing Automation- Business editors can make use of marketing automation feature to automate several steps and process which saves time like sending email when specific goal is triggered and etc.
  13. Experience profile- A profile is created for each site visitor (anonymous/known) and stores all related information into Experience Profile section while fetching the values from experience database(xDB).
  14. Helix/Habitat (Design principles)-
    1. Helix is a set of overall design principles and conventions for Sitecore development.
    2. As more and more people and organisations adopt the Helix conventions and principles, it will become a Sitecore standard.
    3. This means that people who are familiar with the conventions or the Habitat example will be able to work more easily on other convention-based projects with minimal training
    4. It will be easier for Sitecore Product Support to understand projects built using the conventions, enabling them to resolve issues more quickly.

Thanks for reading and see you in my next post!

Happy learning 🙂

Sitecore WFFM custom save actions not working in CD environments

Recently we had an issue in UAT site where WFFM custom save action was found not working on CD servers, but it was absolutely fine on CM server.

WFFM-SaveAction

After checking we found that settings that are required to be done on Sitecore.Forms.config on CD servers were missing, also- we observed that “Custom Action” checkbox was not checked on the custom save action item.

So, here are couple of things to double check when we see custom save action not working in CD servers:

  1. Make sure “Client Action” is checked on WFFM custom save action.ClientAction
  2. Make sure to configure CD server config as per WFFM Installation guide which includes:
    • On all the CD servers, in the \Website\App_Config\Include\Sitecore.Forms.Config file, remove or disable the following sections:
      • In the <sitecore> section, remove:
      • <!—HOOKS–>
        <hooks> <!—remote events hook–>
        <hook type=”Sitecore.Form.Core.WffmActionHook, Sitecore.Forms.Core”/>
        <hooks>

      • In the <events> section, remove:
      • <!–Remote events handler–>
        <event name=”wffm:action:remote”>
        <handler type=”Sitecore.Form.Core.WffmActionHandler, Sitecore.Forms.Core” method=”OnWffmActionEventFired” > <param name=”actionManager” ref=”/sitecore/wffm/wffmActionExecutor” /> </handler>
        </event>

      • Add the following node to the <settings> section:
      • <setting name=”WFM.IsRemoteActions” value=”true” />

      • Configure the following node according to the name of the connection string related to the target database. For example “web”.
      • <setting name=”WFM.MasterDatabase” value=”web” />

Hope this helps!

Happy learning 🙂

SXA redirect URL with country code

It is important to redirect user to new page from old page when we create new version of an existing web page, it helps both users and search engines to get redirected to a new URL from the one they originally requested.

sxa-redirects

There are several ways to setup redirects in Sitecore solution, with Sitecore SXA we have redirect tool in place that facilitates setting up old and new URLs in Sitecore. We can use the mapping tool to set up a 301/302 or server transfer redirect.

Recently we worked on setting up redirects using SXA redirect tool, for most of the redirects we had country code in the old URL.

Here are some example URLs:

Old URLen-au/sample-old-page-name   New URL– /new-page-name

Old URLen-au/mypage/pagelisting   New URL– /newpagelisting

What we observed that after setting up old URLs which has country code on it- all such URLs were redirecting to 404 page.

We can fix this by appending “sc_lang” querystring parameter to the new URL with the target country code, see below examples for ref:

Old URL– /sample-old-page-name   New URL– /new-page-name/?sc_lang=en-AU

Old URL– /mypage/pagelisting   New URL– /newpagelisting/?sc_lang=en-AU

After this redirects works as expected.

I hope this helps.

Happy Learning 🙂

AMP Integration with Sitecore

In my previous post on AMP we discussed about what is AMP (Accelerated Mobile Pages) all about, advantages of using AMP,constraints and some of the basic things which we should consider while using AMP with Sitecore.

As part of this blog post- i would like to go further and see how the integration of AMP can be done with Sitecore.

amp-project

Before we start i want to re-iterate some of the rules and constraints that comes with AMP and obviously all for good reasons.

  • No inline styles
  • All CSS in AMP Page should not be more than 50 KB
  • No custom JS plugin (iframe)
  • Strict validation rules and etc.

We have completed one AMP implementation successfully and want to share how we executed it with Sitecore. We targeted home page as our primary landing page and based on the analytics data we had business idea was to start with home and get some performance improvements there.

Thanks to Sitecore stack exchange which gave me idea on how to get started with this- https://sitecore.stackexchange.com/questions/1597/how-do-i-implement-accelerated-mobile-pages-amp-with-sitecore

Here are the steps we followed in our execution journey.

  1. Create AMP specific device layout to separate AMP and Non-AMP page and we leveraged query-string parameter to differentiate the layout- in our case we used querystring “amp=true” for the same.AMP-DeviceLayout
  2. Sitecore Page layout- As next step we created a new Sitecore layout file which was different from the regular layout file, you can refer the basic version of AMP HTML here
<!doctype html>
<html amp lang="en">
  <head>
    <meta charset="utf-8">
    <script async src="https://cdn.ampproject.org/v0.js"></script>
    <title>Hello, AMPs</title>
    <link rel="canonical" href="http://example.ampproject.org/article-metadata.html">
    <meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
    <script type="application/ld+json">
      {
        "@context": "http://schema.org",
        "@type": "NewsArticle",
        "headline": "Open-source framework for publishing content",
        "datePublished": "2015-10-07T12:02:41Z",
        "image": [
          "logo.jpg"
        ]
      }
    </script>
    <style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
  </head>
  <body>
    <h1>Welcome to the mobile web</h1>
  </body>
</html>

Also, you can have the same placeholders what you have defined in regular layout file, thing which you have to make sure is that you are aligned with the HTML which AMP follows.In addition to this you have to add all the AMP plugins in your layout file, this is again based on what feature you are building as part of AMP page, some of the plugins which we used are:

  1. amp-sidebar
  2. amp-accordion
  3. amp-carousel
  4. amp-social-share

https://cdn.ampproject.org/v0/amp-sidebar-0.1.js
https://cdn.ampproject.org/v0/amp-accordion-0.1.js
https://cdn.ampproject.org/v0/amp-carousel-0.1.js
https://cdn.ampproject.org/v0/amp-social-share-0.1.js

3. Linking AMP and Non-AMP versions– In some cases, you might want to have both non-AMP and an AMP version of the same page, If Google Search finds the non-AMP version of that page, how does it know there’s an AMP version of it?

From https://www.ampproject.org/docs/fundamentals/discovery  – In order to solve this problem, we add information about the AMP page to the non-AMP page and vice versa, in the form of <link> tags in the <head>

Add the following to the non-AMP page:

<link rel="amphtml" href="https://www.example.com/url/to/amp/document.html">

And this to the AMP page:

<link rel="canonical" href="https://www.example.com/url/to/full/document.html">

4. Renderings- Next step would be create separate renderings for the components you are planning to add as part of AMP version of your page. This is to make sure we can support both AMP and Non-AMP versions, prepare list of components that need to be converted to AMP and organize accordingly in Sitecore.

5. Set the presentation layout– Next step is to set the presentation of the page, in our case we had two presentations for the same page- one set for Default layout and one for AMP (Mobile specific) with different set of renderings.

6. Data Bind– As in our case page was already there- we didn’t do anything different to bind the data- we just pass the same data models to AMP renderings and we were all set. You just need to make sure you are calling correct renderings based on the device.

7. Test and Validate- Once you are done with the implementation you need to make sure that AMP page is working as expected, there ware two ways you can verify AMP page- in this case as we used different device for AMP with querystring- we just need to open the URL with correct querystring, so for example- if your page URL is http://www.something.com , then you can access AMP version of it using http://www.something.com/?amp=true

As part of your test you also make sure to run the validations to see if your AMP page version is aligned with the guidelines of AMP. In order to validate the page you can use browser developer console, for example- if your AMP page URL is http://www.something.com/?amp=true , you can append #development=1 to check for any validation errors- http://www.something.com/?amp=true#development=1, see the below AMP validation errors for ref:

validator_errors

8. Deploy–  Once the AMP changes are deployed it may take some time to crawl the page, and once the page is submitted to google you can see your AMP version in google search result with the lightening badge next to it.

google-lightning-badge

URL to verify if page is valid AMP or not- https://search.google.com/test/amp  and provide you AMP page URL.

Valid-AMP

Notes:

  • After the deployment we were able to see the AMP lightning badge in google search results- but few days after it was missing from google search results- we checked this and found that as content authors added some inline styles to one of the field which was making AMP not to submit the page to google because of AMP validation errors.
  • AMP can be used with both Mobile and Desktop, however it is more specific to Mobile user experience to get higher performance and engagement and reduce the bounce rates.
  • If you want your visitors to see AMP version even when the hit the page directly, this can be achieved by adding some device detection rules in Sitecore, we can identify the requesting device and based on which context device can be updated dynamically in Sitecore.

Next Step- As a next step we are checking on making AMP page responsive, but it depends on the components as some components heavily relies on custom JS plugins which can’t be integrated with AMP, there are several components available in AMP as well which can be leveraged, but if same UI & functionality can be achieved while making page responsive can only be confirmed after analyzing existing controls from AMP library- https://www.ampproject.org/docs/reference/components

Making AMP page responsive comes with an advantage that you don’t have to maintain two different versions of the page which make the maintenance part easy- but we should also make a note that we have to work within boundary of AMP guidelines- which sometimes can be a challenging part for responsive design.

I hope this would be useful for guys who are starting with AMP in Sitecore.

Please share your feedback and comments.

References:

Happy learning 🙂

Introduction to AMP and Sitecore

Performance of application is one of the important business KPI (Key Performance Indicators) which heavily contributes to the success of business.There are ways to improve the performance of the website like performing optimization, resources upgrade and etc.

amp

Apart from traditional approaches to improve the performance, there is a lot of buzz and talk going on for AMP (Accelerated Mobile Pages- powered by Google ) these days.

As per wikipedia– “The Accelerated Mobile Pages Project (AMP) is an open-source website publishing technology designed to improve the performance of web content and advertisements. The AMP Project led by Google is a competitor to Facebook’s Instant Articles,[1] and includes several other large search, social and web publishing platforms around the world.”

As part of this blog post– I would like to discuss if AMP can be leveraged for Sitecore applications, advantages and disadvantages and what are some key points to be considered before we plan to integrate AMP with Sitecore.

Advantages of AMP:

  • Speed and Performance-AMP provides a great user experience across many platforms
  • AMP complaint content always gets displayed first in search(organic search).
  • Increased mobile device site loading.
  • Boost in Ranking.
  • Reducing the page bounce rate and better conversions.

Constraints:

  • No custom JS/Plugins allowed, which can affect some of the execution efforts like Pagination, listing, search,etc..
  • All CSS in AMP Page should not be more than 50 KB.
  • Multiple Versions required (AMP and No-AMP).
  • Increased development time- Increases developer time in 2 times(AMP and Non AMP layouts).
  • Strict validation rules
  • Inline CSS styles.

To Consider:

Now, before we proceed for Integrating AMP with Sitecore, let’s check following:

  • Impact on Analytics and Sitecore Analytics?
  • How it affects the website functionality, like carousels, products and other features?
  • Impact on Personalization in Sitecore?
  • Do we need separate layout or can be managed with same default layout.

Though we know AMP is a performance booster, but it’s worth to check above points and do a analysis to understand the Integration.

Apart from just AMPiying your website another important factor is to analyze and understand what pages should be migrated to AMP like:

  • Home page
  • Landing pages and other top performing pages which contribute to the overall business.

Also, when when AMP should be served?- when user is trying to search contents from Google- via organic search(this is default behavior) or when user hit your page directly is a point of discussion and depends on business requirements, Let’s discuss above points as part of my next post on AMP.

Case Studies:

Here are some case studies are available and can be used as reference to understand it better.

I am very excited about AMP and it’s integration with Sitecore, i am pretty sure you guys are too?. I hope this give you a starting point and makes you think about AMP and how it can be leveraged with Sitecore.

References:

Happy learning 🙂

Creating items into multiple locations using SPE

When we work with Multisite solution where in the same Sitecore instance we have different sites for different regions/country, or when we go with several micro sites configuration based on Master site, there are scenarios when we have to create new item(s) based on specific template(s) on all the sites that has been created as part of the instance.

There is absolutely no issue when we are dealing with few sites and pages, but how about when we have more sites? and what if we have to create more than one item under each site?

As a solution we can go to each site node and create the expected items manually, but this approach is going to take good amount of time to complete the full process.

Sitecore Powershell Extensions-1

Solution:

Instead we can leverage Sitecore PowerShell Extensions (SPE) to perform this activity, this is much fast and one of the best approach to complete this operation.

For example– If we want to add two items based on two different templates on the same Sitecore Instance, you can use the following script for that and this will get the job done.

Get-Item master: -Query "/sitecore/content//*[@@templatename='Home Page']" | ForEach-Object {
$newpath= $_.FullPath
$item = New-Item $newpath -Name TestArticle -type "/sitecore/templates/User Defined/Sandbox/Article"
$item = New-Item $newpath -Name FAQ -type "/sitecore/templates/User Defined/Sandbox/FAQ"
}

Sitecore Powershell Extensions

In the above example what i have done is:

  1. Querying all the home nodes under /sitecore/content – based on “Home Page” template.
  2. Taking each home item as context and running “New-Item” SPE command to create an item based on template passed.
  3. As we are running two commands, two items will get created under each site.

Thanks to Michael West and Adam Najmanowicz for this great module.

Hope this is helpful and can save someone’s time who is trying to do something similar.

Happy learning 🙂

References:

  1. https://doc.sitecorepowershell.com/
  2. https://sitecorepowershell.com/

 

Sitecore Basics- Introduction to Personalization

The scope of this blog post is to give an idea about personalization in Sitecore, why it’s required and steps to create  and configure personalization for the components, this is for beginners who are trying to understand the concept and how it can be implemented.

Personalization enables you to deliver targeted content to your visitors. For example, you can implement rules that show personalized content to visitors based on their browsing behavior and their accumulated profile values.
This is really important as you don’t want to show something to users which really doesn’t makes any sense to them.

Sitecore-Personalization

As an example- For an e-Commerce application as an business you want to show relevant information to users to get most of the conversions, this depends on number of factors, some of them includes:

  • User behavior
  • Location
  • Goals users have triggered.
  • Anonymous Vs Logged in users
  • Based on Subscription
  • Showing different banner images.

Sitecore XP lets you choose from several personalization approaches:

  1. Rules-based personalization: You define the conditions under which content is delivered to a customer. For example, you can set rules based on the IP address or physical location of your visitors, the keywords they use to reach your site, their mobile device, or the goals that they achieve on your website to determine the content that is displayed.
  2. Adaptive personalization- Use visitor profiles and pattern-card matching to dynamically adapt the content shown to visitors in real time. You can set adaptive personalization rules in Sitecore XP’s Rules Set Editor.
  3. Historical personalization: You can set rules that personalize content based on a contact’s historical or past behavior, rather than their actions from the current session (after all, context is what comes before and after the present).
  4. Test and then personalize: With Sitecore XP, you can use A/B and multivariate testing to assess your content and use the test results to optimize for conversion rates against your site’s goals. You can also use testing to assess which type of content works best with certain segments of your visitors.
  5. Journey-based personalization: Design user journeys with Sitecore XP using advanced business logic, and use them to help assess where your customers are in their journey with your brand. Then you can use triggers to advance them through their journeys in context of how far along they are.

We use Rule set editor (https://doc.sitecore.net/sitecore_experience_platform/digital_marketing/personalization/the_rule_set_editor ) to set the rules and action to perform and configure personalization for the individual components.

There are several out of the box categories which we can use to personalize the components, which includes:

  1. Campaigns
  2. Channels
  3. Date
  4. Device
  5. Fields
  6. GeoIP
  7. Tracking
  8. Visit and etc.

Personalizing the Component:

In order to personalize the component we have to make sure that the component which you are targeting to personalize should support datasource, this would help us in assigning different contents based on different criteria set.

Here are the steps to configure personalization for specific component(s):

  1. Select the component that you want to personalize, you can select the component either from presentation or from Experience editor.Personalization-1
  2. Select the component and click on Personalize button.
  3. Click on the “New Condition” button and add the rule which you want to add based on the requirement.
  4. Click on Edit button and add the rule.Personalization-2
  5. As an example- i am adding the rule which is based on field name compares to specific value.Personalization-3
  6. We can also define the default or fallback component datasource, if none of the conditions matches the default will be used.Personalization-4
  7. Once the configurations are done on the component, we can see an indicator in the presentation which shows that personalization has been applied to the specific rendering/component.Personalization-5
  8. We can personalize the component from experience editor as well.Personalization-6
  9. Now based on the condition which is added on the component, related content will be rendered else the default content will be displayed.

 

Custom Personalization:

There are certain scenarios where out of the box personalization which are available are not enough to handle the business scenarios, in those cases we have to think about creating custom personalization rules.

We need to create a class that inherits from Sitecore.Rules.Context and implement the Execute() method,and this is where all the business rule exits for the custom rule. We will be covering in a separate blog post about how to create custom personalization rule and applying it on the renderings.

Hope this helps.

Happy learning and wish you all a very Happy New Year 2018 🙂

References:

https://www.sitecore.net/solutions/personalization-segmentation

https://doc.sitecore.net/sitecore_experience_platform/digital_marketing/personalization