I have the following scenario on Sitecore 8.2 (MVC Project) I have a scaled Sitecore (CM/CD), and after the user hits a page on CD Server, it needs to update a Sitecore Item, that contains a field called Counter and this must be republished as well, triggered by the code, at the same time.

I know it's possible to perform this operation using Javascript (Sitecore Services Client), but I'm afraid of using that due to Security. Which would be the best approach to perform that?

Note that, I cannot use .GetDatabase("Master")

Thank You

  • Are you saying that every time that someone visits your site, you want to update an item on master, and then publish?
    – Chris Auer
    Aug 25, 2017 at 1:09
  • Is the Counter field going to be incremented with each page view?
    – Teeknow
    Aug 25, 2017 at 1:49
  • 6
    Can you provide some context as to why you need to do this Jose? This sounds like all kinds of bad practice. Usually if you are tracking page views, why wouldn't you just track this with Sitecore analytics? Some context will better describe your problem and then somebody can provide a better suggestion for a solution to your underlying issue. Aug 25, 2017 at 2:44
  • 2
    I don't know the details of the use case, but in general I agree with the above, this is not the correct way to solve this problem, for performance and security reasons. Aug 25, 2017 at 6:37
  • 1
    Jose are you using xDB or CMS Only? Aug 25, 2017 at 16:07

2 Answers 2


Assuming you have xDB enabled you could perhaps use MongoDB to store your data instead.

There look to be a few approaches for doing this:

1) custom page events:

This looks like your best bet, Here are Sitecore's official docs for this: https://doc.sitecore.net/sitecore_experience_platform/developing/marketing_operations/events/register_a_page_event_programmatically

You can then do something like:

MyPageDataService service = new MyPageDataService();
service.MyPageDataService("Goal", "Donated", "£100", string.Empty);

Some examples from around the web of doing this: https://pramisoni.wordpress.com/2017/02/27/sitecore-analytics-tracking-on-click-of-events/ https://developers.coveo.com/display/public/SitecoreV3/Handling+Custom+Events;jsessionid=A59AE33C36B1AB36ED6906785D67547C


2) a page aggregation table:

This looks more complex to do:


  • I like this better! +1
    – Teeknow
    Aug 25, 2017 at 16:43
  • Hi, the ideia using mongo is good, but the user must be able to override or reset this number as well , i will take a look on those examples
    – Jose Neto
    Aug 25, 2017 at 18:17

If you have xdb enabled see Adam Seabridge's post

I think I would keep this data in a separate sql table. Sql has an atomic increment operation which is something you'll want for this. You also probably don't want that field to be editable in any way by a content editor. Then you would be dealing with a connection string to decide where to pull/write the data based on the environment. I do generally try to avoid a custom db outside of Sitecore but I'm not seeing a great alternative.

As far as I know there is no atomic increment option for a Sitecore field. You might be able to get away with a custom api using a field if you lock before reading the number of times a donation happened and then update it but it just seems like a lot of hoops to go through to edit the master db to then publish that up to the web db. Putting this in a field would also give me cause to pause when it comes to anything that would by default update the master db (submitting a test donation while previewing the page).

  • Hello, one of the requirements is that the field should be editable , that is why i first thought, on edting the master and publishing the web
    – Jose Neto
    Aug 25, 2017 at 18:27
  • @Jose that makes sense. This is an interesting use case. If it does need to be content manageable and update based on functionality I don't have a great answer. If it just needs to be able to be reset maybe you can go with Adam's answer but allow the content editor to set a date that can be used to count donation events from that date onward?
    – Teeknow
    Aug 25, 2017 at 20:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.