-
-
Notifications
You must be signed in to change notification settings - Fork 369
Custom service init EN
We now tackle the most interesting part, creating personalized service !
Let's go straight to the heart of the matter, to add a personalized service add this code (after the initialization code of tarteaucitron) :
tarteaucitron.services.mycustomservice = {
"key": "mycustomservice",
"type": "ads|analytic|api|comment|other|social|support|video",
"name": "MyCustomService",
"needConsent": true,
"cookies": ['cookie', 'cookie2'],
"readmoreLink": "/custom_read_more", // If you want to change readmore link
"uri": "", // a link to the tool's official web page
"js": function () {
"use strict";
// When user allow cookie
},
"fallback": function () {
"use strict";
// when use deny cookie
}
};
(tarteaucitron.job = tarteaucitron.job || []).push('mycustomservice');
tarteaucitron.services.mycustomservice = {
-> This line is used to declare the new service, replace "mycustomservice" by a name that represents your service.
"key": "mycustomservice",
-> This line is used to define the key of the new service, the key must be identical to the name of the service indicated previously.
"type": "ads|analytic|api|comment|other|social|support|video",
-> This line allows you to define the type of service you want to integrate, keep only the one that represents your service (if you do not find anything corresponding to your service then keep "other").
"name": "MyCustomService",
-> This line is used to define the name that will be displayed in the user interface.
"needConsent": true,
-> This line allows you to define whether the user's authorization is required before loading the script (true to comply with the GDPR)
"cookies": ['cookie', 'cookie2'],
-> This line is used to list the cookies saved by the service in order to make the information available to the user.
"readmoreLink": "/custom_read_more",
-> This optional line allows you to change the redirection of the "find out more" link (by default it redirects to the URL indicated in "readmorelink" when initializing tarteaucitron).
"js": function () {
"use strict";
// When user allow cookie
},
-> This function is launched when the user accepts cookies from this service.
"fallback": function () {
"use strict";
// when use deny cookie
}
-> This function is launched when the user refuses cookies or has not yet accepted them
(tarteaucitron.job = tarteaucitron.job || []).push('mycustomservice');
-> This line is used to define the new service as active.
Currently the code is functional, we can activate or not cookies via tarteaucitron however even if the user accepts cookies no changes are visible because the function provided for this purpose is empty.
To find out what to put in this function, refer to the Function - cookies allowed part.