2

I am trying to register a button click event on a page. For this I created a custom click event under /Settings/Analytics/Page events/ and assigned it on a page.
But the problem is: button event gets registered in xDB at session end though the button was never clicked. Looks like Sitecore flushes all the events registered on the page.

I want authors to create custom page events and assign to a page, for example, "CTA Click", "Register Event click", "Learn More click" but register programmatically through javascript click events and avoid other events to flush to xDB.
I am able to call my custom register event from javascript click as below:

 function trackClick(){
    var dataValue = { "name": this.getAttribute("name"), "data": this.getAttribute("data"), "text": this.getAttribute("datatext"),"itemId": $('#hidItemGUID').val() };
    var valstring = JSON.stringify(dataValue);
     $.ajax({
        cache: false,
        url: "/Website/TrackEvents.aspx?query="+valstring,
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        success: function (data) {
            alert("success");
        },
        error: function (data)
                {
            console.log(data);
                }

});

But I am looking to avoid registering any event which are attached to the page but not necessarily triggered by the visitor. Any pointers on this?

Also, in xDB I noticed there are page events getting recorded with "Long running request" as the event name. Any clues where does this come from and how can I avoid?

2

If you don't want to trigger a page event while hitting a page, then you shouldn't associate pages with events. Instead your item template could contain a field that defines which page events to trigger on button click. Then TrackEvents.aspx will need to find that field and register those page events on the page using Sitecore.Analytics.Tracker.CurrentPage.Register() method.

Regarding "Long Running request" page event, it gets triggered when a request runs longer than specified by Analytics.LongRunningRequest setting in Sitecore.Analytics.Tracking.config (default value is 5 seconds). It helps to detect pages that need to be optimized and you should not disable it unless you have a good reason for that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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