Utilizing the TRUENDO JavaScript API and Cookie Callback Functions
Introduction#
The TRUENDO Consent Management Platform (CMP) provides powerful JavaScript APIs and callback functions that allow you to enhance user interactions and integrate custom functionalities into your website. By leveraging these tools, you can create custom buttons, control the Privacy Widget, react to changes in cookie settings, and ensure seamless integration with services like Microsoft Dynamics.
This comprehensive guide will walk you through the steps to use the TRUENDO JavaScript API and implement cookie callback functions, providing code examples and best practices.
1. Prerequisites#
Before you begin, ensure you have:
- Access to Your Website's Code: Ability to modify HTML, JavaScript, and integration scripts.
- TRUENDO CMP Integrated: The TRUENDO CMP script should already be implemented on your website.
- Basic Understanding of JavaScript: Familiarity with JavaScript functions and event handling.
2. Understanding the TRUENDO JavaScript API#
The TRUENDO JavaScript API allows you to create custom interactions with the CMP, such as opening the Privacy Widget or toggling consent categories directly from your website.
A. Creating Custom Buttons
You can create custom buttons or links that interact with the TRUENDO CMP. This is useful for adding privacy controls in specific areas of your website.
B. Opening Tabs with a Link
Use the following code snippets to open different parts of the Privacy Widget:
1. Open Privacy Widget
<a href="javascript:Truendo.openPrivacyPanel()">Privacy Center</a>
2. Open the Privacy Tab
<a href="javascript:Truendo.openYourRights()">Privacy Policy</a>
3. Open the Cookies Tab
<a href="javascript:Truendo.openCookieSettings()">Cookie Manager</a>
C. Toggling Service Categories
You can toggle specific service categories programmatically using the API. This allows users to change their consent preferences directly.
1. Social Content
<a href="javascript:window.Truendo.toggleContent();">Toggle Social Content</a>
2. Marketing
<a href="javascript:window.Truendo.toggleMarketing();">Toggle Marketing</a>
3. Statistics
<a href="javascript:window.Truendo.toggleStatistics();">Toggle Statistics</a>
4. Additional Features
<a href="javascript:window.Truendo.addFeatures();">Toggle Additional Features</a>
5. Preferences
<a href="javascript:window.Truendo.togglePreferences();">Toggle Preferences</a>
D. Other API Calls
Unblocking Services
This call reruns the CMP unblocking functionality based on the user's current consent choices. It can be useful when new content is loaded dynamically.
window.Truendo.runUnblockService();
3. Implementing Cookie Callback Functions#
The TRUENDO CMP allows you to execute custom code whenever a user changes their cookie settings. This can be achieved either by defining a global callback function or by adding an event listener.
A. Using the Global Callback Function
Create a global function named TruendoCookieControlCallback
to execute custom code upon changes in cookie settings.
Example:
<script type="text/javascript">
function TruendoCookieControlCallback(cookieSettings) {
if (cookieSettings.ack) {
console.log('Cookie dialog acknowledged');
}
if (cookieSettings.necessary) {
console.log('Necessary cookies enabled.');
}
if (cookieSettings.preferences) {
console.log('Preference cookies enabled.');
}
if (cookieSettings.statistics) {
console.log('Statistics cookies enabled.');
}
if (cookieSettings.marketing) {
console.log('Marketing cookies enabled.');
}
if (cookieSettings.social_content) {
console.log('Social Content cookies enabled.');
}
}
</script>
B. Adding an Event Listener
Alternatively, you can add an event listener for the TruendoCookieControl
event to the window
object.
Example:
<script type="text/javascript">
window.addEventListener('TruendoCookieControl', function (event) {
// Cookie settings accessible via event.detail
var cookieSettings = event.detail;
if (cookieSettings.ack) {
console.log('Cookie dialog acknowledged');
}
if (cookieSettings.necessary) {
console.log('Necessary cookies enabled.');
}
if (cookieSettings.preferences) {
console.log('Preference cookies enabled.');
}
if (cookieSettings.statistics) {
console.log('Statistics cookies enabled.');
}
if (cookieSettings.marketing) {
console.log('Marketing cookies enabled.');
}
if (cookieSettings.social_content) {
console.log('Social Content cookies enabled.');
}
});
</script>
C. Accessing the Cookie Settings Object
You can access the cookie settings at any time via the read-only Truendo.cookieSettings
property.
Example:
var currentCookieSettings = Truendo.cookieSettings;
console.log(currentCookieSettings);
4. Integrating with Microsoft Dynamics#
When integrating TRUENDO CMP with Microsoft Dynamics, you can use the cookie callback function to control how Microsoft Dynamics tracking behaves based on user consent.
A. Important Considerations
Important: For this integration to work properly, Microsoft Dynamics must be added to a category other than Marketing (e.g., Statistics).
- Reference: Microsoft Dynamics Documentation
B. Callback Example for Microsoft Dynamics
Place the following script below your Microsoft Dynamics script:
<script>
function TruendoCookieControlCallback(cookieSettings) {
if (cookieSettings.necessary) {
// Run code here if this category is opted in
}
if (cookieSettings.preferences) {
// Run code here if this category is opted in
}
if (cookieSettings.statistics) {
// Configure Microsoft Dynamics tracking based on consent
MsCrmMkt.reconfigureTracking({ Anonymize: false });
} else {
// Anonymize tracking if user does not consent
MsCrmMkt.reconfigureTracking({ Anonymize: true });
}
if (cookieSettings.marketing) {
// Run code here if this category is opted in
}
if (cookieSettings.social_content) {
// Run code here if this category is opted in
}
}
</script>
Explanation:
- The function checks the user's consent settings and configures Microsoft Dynamics tracking accordingly.
- If the user has not consented to the Statistics category, tracking is anonymized.
5. Conclusion#
By utilizing the TRUENDO JavaScript API and cookie callback functions, you can create a more dynamic and user-friendly experience on your website. These tools allow you to:
- Provide users with easy access to privacy settings.
- React to changes in consent preferences programmatically.
- Integrate third-party services like Microsoft Dynamics in a compliant manner.
Always ensure that any custom code you implement respects user consent and complies with relevant data protection regulations.
6. Support and Resources#
-
TRUENDO Support:
- Website: https://www.truendo.com/
- Documentation: https://docs.truendo.com/
- Email: support@truendo.com
-
Additional Resources:
- TRUENDO CMP Integration Guide: Integration Guide
- Microsoft Dynamics Cookie Consent: Microsoft Dynamics Docs
- JavaScript Event Handling: MDN Web Docs - addEventListener
- Data Privacy Regulations: Ensure compliance with GDPR, CCPA, and other relevant laws.
End of Guide
If you have any further questions or require assistance with specific configurations, please don't hesitate to reach out to TRUENDO Support or consult the resources provided.