In the last blog post we looked at Tealium tag management for Sitecore. In this post we will cover customization available to enabled computed fields. By default you have access to the following out of the box fields:
item_id: “{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}”
item_language: “en”
item_name: “Home”
item_path: “/sitecore/content/home”
item_template_id: “{32B25AF5-4043-4776-BC20-098339109A4C}”
item_template_name: “Home”
We also saw in the last post about how to add custom tags with fixed values (site_currency: [“USD”,”EUR”]). In the next post we will look at template specific tags and how we can render them.
For the purposes of this blog post, lets assume that we want the item url to be rendered as a tag. In order to make this available globally we can enable the Custom UDO property in /sitecore/system/Modules/Tealium Tag Management/Settings/Tealium Settings.
In order to do that we need to write some code which will inherit the IComputedFieldMapper interface.
using System.Collections.Generic; namespace Tealium.Sitecore.TagManagement.Mappings { public interface IComputedFieldMapper { void AddComputedFields(IDictionary<string, object> utagParams); } }
Follow the steps below:
- In your assembly add a reference to the Tealium.Sitecore.TagManagement.dll
- Create a class TealiumComputedFields and inherit the IComputedFieldMapper, be sure to implement that interface
- This will force you to define the AddComputedFields method, here add your code for the tags you would like to render
using Sitecore; using Sitecore.Links; using System.Collections.Generic; using Tealium.Sitecore.TagManagement.Mappings; namespace YOURNAMESPACE { public class TealiumComputerFields : IComputedFieldMapper { public void AddComputedFields(IDictionary<string, object> utagParams) { utagParams.Add("item_url", LinkManager.GetItemUrl(Context.Item)); //Sad part is you get only one of these and if you need to cater to multiple templates or render based on multiple templates //you have to end up using switch/if statements to do conditional logic based on template //switch (Context.Item.TemplateName) //{ // case "Product": //logic // break; // case "Article": //logic // break; //} } } }
- Edit /sitecore/system/Modules/Tealium Tag Management/Settings/Tealium Settings item and check the Enable Custom UDO check box
- Set the Custom UDO Type based on the information from your assembly (YOURNAMESPACE.TealiumComputerFields,YOURASSEMBLY)
Sad part is that you only get one custom computed fields library and if you need to cater to multiple templates or render based on multiple templates, you have to end up using switch/if statements to do conditional logic based on template.
Here is the output generated:
Sitecore Experience Platform
As usual if you have any questions or comments, please be sure to ping me.
Thanks.