3

After enabling the Sitecore 9 analytics, when I open the Experience Profile, I see all the WebApi ajax calling as page view events or page events in the Experience Profile.

Why this is happening?

Is there any way to prevent that?

BTW, in our system, session is enabled for WebApi calls.

3 Answers 3

3

The best way to tackle this is to add an Action Filter on your Controller actions to prevent the events from showing up in your Analytics Reports.

Filter code:

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true)]
public sealed class DisableTrackingAttribute : ActionFilterAttribute
{
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        if (!Tracker.IsActive || Tracker.Current == null)
        {
            Tracker.StartTracking();
        }

        if (Tracker.Current != null && Tracker.Current.CurrentPage != null)
        {
            Tracker.Current.CurrentPage.Cancel();

            base.OnActionExecuting(filterContext);
        }
    }
}

Example Controller code:

[ServicesController]
public class AnalyticsController : ServicesApiController
{
    [HttpPost]
    [DisableTracking]
    public dynamic TriggerPageEvent(string eventId, string setUrl = null)
    {
        Some logic
    }
}
1
  • Hi, thanks for you reply. I found my solution through your answer. Although I implemented it using pipeline.
    – Foysal
    Jun 4, 2018 at 9:07
0

Take a look on page event settings for "Page Visit":

https://doc.sitecore.net/sitecore_experience_platform/digital_marketing/experience_profile/configuring_the_xfile/configure_a_page_event_to_appear_in_the_experience_profile

I think that if you modify "Rules" field you can filter out traffic to web api.

0
0

This is how I have always done it:

<configuration>
    <sitecore>
        <tracking>
          <untrackedPages>
            <!-- Page paths must begin with "/" -->
            <add path="/api/xxxxxx"/>
            <add path="/api/xxxxxx1"/>
          </untrackedPages>
        </tracking>
    </sitecore>
</configuration>

If you want support for wildcard exclusions, there is a module that you can reference.

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.