Skip to content

Introduction

ConsentFriend uses the open source script of Klaro! as consent management script on the frontend. The Klaro! script automatically activates internal and external services on the webpage. ConsentFriend prepares the HTML code of the page so that the automatic execution or loading of external services can be controlled via Klaro! script.

Consent Management

The following steps are prepared by ConsentFriend automatically

To make sure that no tracking scripts and third-party services are loaded without consent, the HTML code of the page has to be modified: For scripts, the type attribute has to be set to or replaced with type="text/plain" (this keeps the browser from executing the script) and a data attribute with the original type has to be added, i.e. data-type="application/javascript". Also a data-name attribute that has to match the name of the service in the Custom Manager Page must be added, i.e. data-name="matomo".

If you enter the external service code in the ConsentFriend service configuration, the code will be prepared for the the automatic activation. ConsentFriend will inject the code at the end of the HEAD or BODY section in the HTML code.

Commercial version of Klaro!

ConsentFriend does not use the commercial server side version of Klaro!. It is not needed and currently not possible to use the commercial version of Klaro! with ConsentFriend.

Custom external services

If you have to place the external services inline on the page, you have to handle the code preparation on your own. External services can be i.e. called by script, img, link, iframe, video or audio tags. All those tags for an external service must contain a data-name attribute, that matches the name of a service of ConsentFriend, i.e. data-name="matomo". If the original tag contains a type attribute it has to be changed to type="text/plain".

script tags

Services with a script tag need an additional data-type attribute with the original type i.e. data-type="application/javascript". When the service refererences an external script by the src attribute, this attribute has to be renamed with data-src.

iframe and img tags

Services with an iframe or an img tag need an additional data-src attribute with the original src i.e. data-src="https://www.youtube.com/embed/M7lc1UVf-VE". The original src attribute has to be removed. Since the type attribute is not valid for iframe tags, it can be removed there.

ConsentFriend will hide an iframe based service and display a placeholder with an activation button in place. This feature is called Contextual Consent and is used since ConsentFriend 1.2.0.

picture, video and audio tags

Images with a srcset attribute and source tags in a picture tag need a data-srcset attribute with the original srcset instead of the srcset attribute. Video and audio tags, as well as their source and track tags need a data-src attribute instead of the src attribute. The poster attribute of a video tag has to be renamed to data-poster. Each of these tags needs the data-name attribute. After the consent, video and audio elements are reloaded with the restored sources.

Services with a link tag need an additional data-href attribute with the original href i.e. data-href="https://fonts.googleapis.com/css2?family=Open+Sans". The original href attribute has to be removed.

Head Script

ConsentFriend inserts the consent management script directly after the opening head tag of each page, where ConsentFriend is enabled. The code is generated with the chunk in the system setting consentfriend.head_script (default: ConsentFriendHeadScript):

<script type="application/javascript">window.consentFriendConfig = [[+config]];</script>
<script defer data-klaro-config="consentFriendConfig" type="application/javascript" src="[[+scriptfile]]"></script>

The chunk can use the following placeholders:

Placeholder Description
[[+config]] The ConsentFriend configuration (services, purposes and translations) as a javascript object.
[[+scriptfile]] The url of the ConsentFriend script with a version parameter.

The name of the javascript variable in the first script tag has to match the data-klaro-config attribute of the second script tag. Otherwise the consent management script starts without a configuration.

To change the code, i.e. to add a nonce attribute for a Content Security Policy, create a chunk with a new name and change the system setting consentfriend.head_script to this name. Don't change the ConsentFriendHeadScript chunk, since it is overwritten during an update of ConsentFriend. MODX tags in the chunk are parsed. Since ConsentFriend 1.10.0 the configuration is inserted after parsing the chunk, so MODX tags in the configuration are not parsed.

The stylesheet of ConsentFriend is inserted before the closing head tag, if the default theme is used.

Default Services

ConsentFriend installs several default services. Some of them use system/context settings that you have to create yourself.

Examples

Example code for external services:

If you want to add a link to the consent management window on a page, you can use the ConsentFriendChangeSetting chunk, that is installed with ConsentFriend:

[[$ConsentFriendChangeSetting]]

The chunk contains the following code:

<a onclick="klaro.show();return false;">[[%consentfriend.services.change_setting? &namespace=`consentfriend` &topic=`services`]]</a>

The link text is the lexicon entry consentfriend.services.change_setting in the services topic. To change the code, create a chunk with a new name and use this chunk instead. Don't change the ConsentFriendChangeSetting chunk, since it is overwritten during an update of ConsentFriend.