loading...

How make a Sitecore solution GDPR compliant

alexdhaenens profile image Alex Dhaenens ・2 min read

Mastering the magic (6 Part Series)

1) How make a Sitecore solution GDPR compliant 2) Why the GDPR and (Sitecore) device detection won’t work together 3 ... 4 3) The almighty sitecore Q? 4) Why combining sitecore and salesforce marketing cloud (SFMC) is a great idea 5) How to resize images from the media library with code 6) How to pass rendering parameters from Sitecore to React

With the first fine being granted to a company since the introduction of the new European GDPR laws, it is time for our own Sitecore solutions to be adapted. Those GDPR laws restrict the tracking of users without the user’s consent, which is mostly done by setting certain cookies. This means that those cookies cannot be set without consent of the user.
In Sitecore, users are tracked by Sitecore Analytics which creates a contact profile containing the information gathered of the user. In order to track users, Sitecore Analytics uses the SC_ANALYTICS_GLOBAL_COOKIE cookie.

Disabling the tracker & cookie

So, in order to make your Sitecore solution GDPR compliant, well, the tracker should not be started, and the analytics cookie should not be set (and removed if it was already set). This can be done easily because for every request without a tracker, the startAnalytics pipeline is started. This pipeline, as the name suggest, starts a whole bunch of things for Sitecore Analytics. If you would analyze the pipeline you would see that there is a processor called CreateTracker. The processor creates the tracker and when creating a tracker the cookie is set, therefor this is where the pipeline should be aborted when the user did not give his or her consent. This can be easily done by inserting a new processor right before the CreateTracker processor:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <pipelines>
      <startAnalytics>
        <processor
          type="YOURPROCESSOR" patch:before="processor[@type='Sitecore.Analytics.Pipelines.StartAnalytics.CreateTracker, Sitecore.Analytics']" resolve="true"/>
      </startAnalytics>
    </pipelines>
  </sitecore>
</configuration>

That processor should abort the pipeline when the user did not give any consent and the Analytics cookie should be removed if it was already be set:

if (SC_ANALYTICS_GLOBAL_COOKIE not allowed)
            {
                if (HttpContext.Current.Request.Cookies["SC_ANALYTICS_GLOBAL_COOKIE"] != null)
                {
                    var myCookie = new HttpCookie("SC_ANALYTICS_GLOBAL_COOKIE");
                    myCookie.Expires = DateTime.Now.AddDays(-1d);
                    HttpContext.Current.Response.Cookies.Add(myCookie);
                }

                args.AbortPipeline();
            }

Aftermath

Because the user is not tracked and the tracker did not start, a lot of things will not work anymore: personalization, device detection, all code using the user profile (via XConnect),… So be aware of this and make sure that your Sitecore solution does not crash and can handle this, especially the abscent XConnect. As it will throw errors telling you that the tracker is not initialized (Tacker.Current is not initialized).
Also on a small side note, this code does block the analytics cookie but to make your site fully GDPR compliant you might need to block other cookies as well (either 3rth party or your own custom ones).

Mastering the magic (6 Part Series)

1) How make a Sitecore solution GDPR compliant 2) Why the GDPR and (Sitecore) device detection won’t work together 3 ... 4 3) The almighty sitecore Q? 4) Why combining sitecore and salesforce marketing cloud (SFMC) is a great idea 5) How to resize images from the media library with code 6) How to pass rendering parameters from Sitecore to React

Posted on by:

alexdhaenens profile

Alex Dhaenens

@alexdhaenens

I'm a full stack software engineer & interested in all engineering things. But I'm really, really, passionate about software

Discussion

markdown guide