In order to be able to use the Sitecore extension, you need a few things:

The Cookie Information Sitecore extension can be found as a NuGet package. You can either download the package, or install it via the Command Line using the following command:

Install-Package CookieInformation.SitecoreExtensions -Version 1.0.4

Alternatively, there are also commands available for other Package Managers:

.NET CLI:

dotnet add package CookieInformation.SitecoreExtensions --version 1.0.4

Package Reference:

<PackageReference Include="CookieInformation.SitecoreExtensions" Version="1.0.4" />

Paket CLI:

paket add CookieInformation.SitecoreExtensions --version 1.0.4

Activating necessary configuration files

Once you have installed the Package with your chosen Command Line tool, you will need to rename a couple of configuration files in order for them to become active and useable.

  • Rename AppSettings.config.disabled to AppSettings.config

  • Rename Pipeline.config.disabled to Pipeline.config

By default, the possible cookie categories available to use are:

  • NECESSARY

  • FUNCTIONAL

  • MARKETING

  • STATISTIC

To assign cookies to each category, go to the following directory in your project:

App_Config/Include/CookieInformation.SitecoreExtensions/AppSettings.config

The first thing you will see is the mappings of cookie categories that looks like the following:

CookieInformation.SitecoreExtensions:NECESSARY
CookieInformation.SitecoreExtensions:FUNCTIONAL
CookieInformation.SitecoreExtensions:MARKETING
CookieInformation.SitecoreExtensions:STATISTIC
CookieInformation.SitecoreExtensions:MISC

You will also see that the most commonly used cookies have been added already to make it easier for you to get up and running. Please note that each key should have a list of cookie names separated by a comma (",").

Additional Settings

There are also some separate additional settings that you can adjust to tailor the integration's behaviour to your own liking:

CookieInformation.SitecoreExtensions:REMOVEOLD

REMOVEOLD will default to false. If it is set to true then cookies in a visitors browser that they have not given consent to will expire. At the same time, it also triggers the Pipeline (found in App_Config/Include/CookieInformation.SitecoreExtensions/Pipeline.config).

CookieInformation.SitecoreExtensions:LOGREMOVAL

LOGREMOVAL will also default to false. If it is set to true then it will log in INFO whenever a cookie is removed due to missing consent.

CookieInformation.SitecoreExtensions:COOKIENAME

COOKIENAME will default to CookieInformationConsent, but otherwise will show the name of the cookie that is set.

CookieInformation.SitecoreExtensions:DISABLECOOKIECONSENTFORAUTHENTICATEDUSERS

DISABLECOOKIECONSENTFORAUTHETICATEDUSERS defaults to true and disables cookie consent functionality for users that are authenticated.

Useful References

@using CookieInformation.SitecoreExtensions.Services
@using CookieInformation.SitecoreExtensions.Settings
@using CookieInformation.SitecoreExtensions.Helpers

Similarly to how you would implement the scripts for Cookie Information on other platforms, you can simply navigate to the Layout of your site and add the below line in the <head> tag:

@Html.Raw(CookieServiceLocator.CookieService.GetConsentScript())

There are a few different ways you can add a cookie. Below are some examples.

@if (CookieServiceLocator.CookieService.ConsentsToCategory(CookieInformationCategories.MARKETING))
{
HttpContext.Current.Response.Cookies.Add(new System.Web.HttpCookie("MyInternalTracking", "TrackingID"));
@Html.Sitecore().VisitorIdentification()
}

You can also add scripts as usual, if you prefer:

@if (CookieServiceLocator.CookieService.ConsentsToCategory(CookieInformationCategories.FUNCTIONAL))
{
<script src="//maps.googleapis.com/maps/api/js?key=@(Sitecore.Configuration.Settings.GetSetting("Google.API"))&amp;callback=initMap" async defer></script>
}

Allowing script to fire immediately upon user acceptance of cookies

If you would like a script to fire immediately on a page as soon as the visitor has accepted a particular cookie category (such as Google), then you can use the following code snippet:

<!-- Google Tag Manager -->
@using (Html.CreateConditionalCookieScript(CookieInformationCategories.STATISTIC, "initGTM()"))
{
<script>
function initGTM() {
(function (w, d, s, l, i) {
w[l] = w[l] || []; w[l].push({
'gtm.start':
new Date().getTime(), event: 'gtm.js'
}); var f = d.getElementsByTagName(s)[0],
j = d.createElement(s), dl = l != 'dataLayer' ? '&l=' + l : ''; j.async = true; j.src =
'https://www.googletagmanager.com/gtm.js?id=' + i + dl; f.parentNode.insertBefore(j, f);
})(window, document, 'script', 'dataLayer', 'GTM-XXXXXXX');
}
</script>
}
<!-- End Google Tag Manager -->

In order for it to work correctly, please remember to change the attribute 'GTM-XXXXXXX' to your own Google Tag Manager ID.

Implementation checklist

  1. A Cookie Information account with a domain added in the platform

  2. An up and running Sitecore project

  3. Extension installed via NuGet or your package manager of choice

  4. Renamed configuration files

  5. Cookies assigned

  6. JavaScript added to <head> tag


Did this answer your question?