How to Enable Session in Sitecore WebApi for Tracker and Analytics

Posted in: Uncategorized |

No comments

INTRODUCTION

I’m developing a Sitecore website for a client where using Angular and WebApi. One of the functionalities is to ensure that search keyword is tracked in Sitecore Analytics. All sounds simple and straight forward, except the Tracker code requires Session to run. And since the code that tracks the keyword is inside your WebApi, it makes it even trickier.

Session is by default not enabled in generic WebApi let alone Sitecore’s one. A great article has been written to allow you to do this:

http://blogs.perficient.com/microsoft/2016/11/sitecore-add-session-to-web-api/

It all works fine except every time you want to use this functionality on different projects, you have to copy/paste the code and redo all over again.

I’ve managed to wrap it into a Sitecore package which you can deploy to various Sitecore websites. A configuration file has also been created so that you can add multiple WebApi controllers without having to change the source code.

HOW TO USE

1. Go to Sitecore Desktop > Installation Wizard and install the SitecoreSessionApi-1.0.zip
2. Go to your Website folder > App_Config > Include > zzzzSitecoreSessionApi and open SitecoreSessionApiConfiguration.xml.

3. Add all your WebAPIs that require session enabled.

<Api>
<Name>AdvancedSearchSitecoreSessionApi</Name>
<RouteTemplate>sitecoresessionapi/advancedsearch</RouteTemplate>
<ControllerToLoad>Search</ControllerToLoad>
<ReadOnlySession>false</ReadOnlySession>
</Api>
<Api>
<Name>MyOtherApi</Name>
<RouteTemplate>sitecoresessionapi/myotherapi</RouteTemplate>
<ControllerToLoad>MyOtherApi</ControllerToLoad>
<ReadOnlySession>false</ReadOnlySession>
</Api>

4. Finally, in your Angular code, to load the WebApi, instead of using /api/[controllername] URL you would use the URL you specify in the RouteTemplate variable above eg. /sitecoresessionapi/myotherapi

DOWNLOAD

Click here to download the package.

SitecoreSessionApi-1.0

 

That’s it! Hope this helps.

Tommy

Written by

A web solution expert who has passion in website technologies. Tommy has been in the web industry for more than 10 years. He started his career as a PHP developer and has now specialized in ASP.NET, SharePoint and MS CRM. During his career he has also been in many roles: system tester, business analyst, deployment and QA manager, team and practice leader and IT manager.

No Comments Yet.

Leave a Reply

You must be logged in to post a comment.

Our Services

We provides you the best Services in our themes.

  • Click on the link below to see a full list of clients which we have developed solutions and provided consultancy for.

    READ MORE

  • We are solution-centered and not application-centered.

    READ MORE

  • Being creative and having fun and yet still delivering a fantastic service is the center of our values.

    READ MORE

  • TFS Consulting Services guarantees delivery that is within budget and deadline or you engage us for free.

    READ MORE

Implementing IT does not have to be difficult.

As long as you have the right methodologies

We have heard a lot of complaints from our clients that IT a lot of the times give them headache. The issues range from over-budget implementation, server is too hard to maintain, application is not user friendly, features not complete and many others. If you have ever experienced similar situations, don’t worry. This is why TFS Consulting Services is here. We exist to help clients implementing a successful IT solution. We have various methodologies which we have proven working in delivering a successful IT implementation. Below is the list of some of our key service offerings:
  • Planning and Methodologies

    Implementing IT solution does not have to be difficult. TFS Consulting Services has a lot of resources on planning and methodologies that will ensure successful delivery of your IT solution. TFS Consulting Services has been around in the web industry for more than 10 years and has experienced all the successes and failures of various type of IT deployment.

    read more

  • Technical Resource

    Do you need a technical resource? TFS Consulting Services can also provide you with technical resource for developing ASP.NET (C# and VB.NET), SharePoint (2003, 2007, 2010, 2013) and MS CRM applications. Our resource is an Microsoft Certified Personnel (MVP) and Microsoft Certified Technology Specialist (MCTS) in all ASP.NET, SharePoint and CRM.

    read more

  • IT Consulting & Advice

    Make sure your IT implementation is robust and scalable. TFS Consulting Services can provide consulting and advice on industry’s best practice on various web-related areas such as website security, design and usability, application-specific (such as SharePoint)’s best practice, Search Engine Optimisation (SEO), coding standards and many others.

    read more

  • Solution Development

    Finally TFS Consulting Services provides you with solution development service. We mainly work with Microsoft technologies (ie. .NET and SQL Server), however we are also capable of developing with PHP and MySQL. If you ever need any business process automation, integration and solution development work,  we are the trusted expert you should go to.

    read more

For more detailed service offerings please visit our Solutions page.

Testimonials

  • I’m happy to recommend Tommy as a knowledgeable and diligent developer.

    Mike Stringfellow, Vivid Group
  • Tommy has a lot of great ideas that can be delivered into great products. It’s a pleasure working with him because he has a broad knowledge about available technologies out there and he knows what’s best for the client’s needs. He just knows how to work effectively and efficiently.

    Teddy Segoro, Student Edge
  • I’ve worked with Tommy over the past 6 months and have found his approach to development (especially SharePoint) absolutely outstanding. Tommy goes beyond the boundries of typical software development with his ability understand what a client requires and then build it into fully fledged software solution. Coupled with his professional “Best Practice” approach, you get Continue Reading

    Michael Bonham, DSC-IT

Contact us

Tommy Segoro
tommy@tfsconsulting.com.au
+61 404 457 754

   

© TFS Consulting Services 2024. All rights reserved.

www.incorporator.com.au