Vijaya Akkenapally
Vijaya Akkenapally

Reputation: 163

How to track click event on server side in sitecore

How to track the user click event on the server side in sitecore? Our requirement is to track few external clicks on the site and register them as goals. I can track the clicks through client side js script but then I would like to achieve this through server side. Any idea as to how to track? Which event\processor actually holds the clicked links info/?

Upvotes: 0

Views: 1381

Answers (2)

Gatogordo
Gatogordo

Reputation: 2635

A click to an external page will not pass through Sitecore anymore, so the system will not be able to track that ootb. Like Marek said, you have a few options to do this yourself. I wrote a blog post on it (https://ggullentops.blogspot.be/2016/02/integrating-addthis-with-sitecore-goals.html) a while ago explaining (with code) how to do this with javascript on the client and a controller to register the goals on the server.

We just post to the controller which takes care of the triggering the goal. Code in short looks like this (check the post for full code - also with obligatory null checks):

var visit = Tracker.Current;
var page = Tracker.Current.Session.Interaction.PreviousPage;

var registerTheGoal = new PageEventItem(goalItem);
var eventData = page.Register(registerTheGoal);
eventData.Data = goalItem["Description"];
eventData.ItemId = goalItem.ID.Guid;
eventData.DataKey = goalItem.Paths.Path;
Tracker.Current.Interaction.AcceptModifications();

Tracker.Current.CurrentPage.Cancel();

Upvotes: 0

Marek Musielak
Marek Musielak

Reputation: 27132

There are no events and no processors which are execute when a link on a page is clicked.

You have 2 options if you want to register external link click as Sitecore goal:

  1. Add onclick javascript background call to the server and send the information about the link which was clicked. Then register it as a goal on server side.
  2. Create "External link" item in Sitecore and link to that page instead of linking to the external page directly. Then add a goal to that page and instead of displaying it, redirect client to the external site.

Upvotes: 1

Related Questions