Migrate from another CMP
Switch from another consent management platform to CookieBeam. Plan the cut-over, decide whether to carry earlier choices across, and know what can't be carried.
Ostatnia aktualizacja:
This page covers the mechanics of replacing another consent tool with CookieBeam. It doesn't tell you whether a choice a visitor made in your previous tool is still valid for what your site does today. That's a legal question for you and your advisers.
What changes for visitors
CookieBeam keeps its own consent record and doesn't read another tool's cookie. After the switch, every visitor without a CookieBeam record is treated as new. In an opt-in region they see the banner again, and optional scripts stay blocked until they choose.
You have two options:
- Ask again. Do nothing extra. Returning visitors see the CookieBeam banner once. Every record is then one CookieBeam collected with your current banner text.
- Carry choices across. Add a small bridge script that reads your previous tool's cookie and writes a matching CookieBeam record. This works for category choices. It doesn't work for IAB TCF strings.
Before you switch
- Create your banner and scan your site, so the inventory and blocking rules are in place.
- List your previous tool's categories and decide which CookieBeam category each one maps to. See Categories and purposes.
- Test on a staging site with a non-production environment. Install that environment's
loader.jsthere. - Remove the previous tool's tag in the same release that adds the CookieBeam loader. Don't run two consent tools on one live page. Both would try to block scripts and set Google Consent Mode.
Install the loader as described in Script tag:
<script src="https://cdn.cookiebeam.com/banner/PUBLIC_BANNER_ID/default/loader.js" data-cfasync="false" data-no-optimize="1" data-no-defer="1" data-no-minify="1" data-noptimize="1" nowprocket="1" data-pagespeed-no-defer="1"></script>
Carry category choices across
The bridge has three parts: read the old cookie, map its categories, and write the CookieBeam record.
<script>
// 1. Read the previous tool's cookie. Adjust the name and the parsing to your tool.
function readPreviousChoice() {
var match = document.cookie.match(/(?:^|; )previous_consent=([^;]+)/);
if (!match) return null;
try {
return JSON.parse(decodeURIComponent(match[1]));
} catch (e) {
return null;
}
}
// 2. Map the previous tool's category names to your CookieBeam category IDs.
var categoryMap = {
performance: 'analytics',
functional: 'preferences',
targeting: 'marketing'
};
// 3. Write the CookieBeam record once the runtime is ready.
window.addEventListener('cookiebeam:ready', function () {
if (window.CookieBeam.validConsent()) return; // a CookieBeam record already exists
var previous = readPreviousChoice();
if (!previous || !Array.isArray(previous.accepted)) return;
var categories = previous.accepted
.map(function (name) { return categoryMap[name]; })
.filter(Boolean);
if (categories.length === 0) return;
window.CookieBeam.hide(); // first: close the banner
window.CookieBeam.acceptCategory(categories); // then: write the record
}, { once: true });
</script>
The example assumes the old cookie holds JSON with an accepted array. Yours will differ.
Put the bridge inline in the page, before the CookieBeam loader tag. cookiebeam:ready fires once. A bridge added later, for example by a tag manager, can miss it.
Call hide() before acceptCategory()
The order matters for your records. CookieBeam labels each record with how it was collected:
Banner state when acceptCategory() runs | collectedVia |
|---|---|
| The consent banner is open | banner |
| The preferences window is open | preferences |
| Nothing is open | api |
For a visitor without a record, the banner is usually already open when cookiebeam:ready fires, and acceptCategory() doesn't close it. If you call acceptCategory() first, the carried-over choice is stored as a banner click, which it wasn't. Call CookieBeam.hide() first. The record is then stored as api, and you can tell carried-over choices apart from real banner choices. collectedVia is a field of the consent record. See Read consent on your server.
The banner can appear for a moment before the bridge closes it.
What the bridge does and doesn't do
- It writes a new CookieBeam record dated when the bridge runs. The date of the original choice isn't carried over.
- It skips visitors who already have a valid CookieBeam record, so you can leave it in place for as long as old cookies are around.
- It only carries accepted categories. For a visitor who rejected everything in the previous tool, nothing is written and the banner asks again.
- It runs in the browser. Records in your previous tool's database aren't imported.
- It never runs in opt-out and notice regions. There, CookieBeam writes a default record when the page loads, before
cookiebeam:ready, andvalidConsent()is alreadytrue. To carry choices across in those regions, the bridge has to treat a record withisDefaultState: trueas no record. Test that path on your staging site first.
See the Browser API for hide(), validConsent() and acceptCategory().
IAB TCF: TC strings don't carry over
If your previous tool was an IAB TCF CMP, it stored a TC string in the euconsent-v2 cookie. CookieBeam doesn't adopt it.
CookieBeam's TCF module reads euconsent-v2 when it starts, and keeps a string only if CookieBeam wrote it. It deletes a string written by another CMP when all of these hold:
- TCF applies to the visitor.
- The vendor list has loaded.
- The browser holds no CookieBeam TC string next to it.
The cookie is then removed on every domain and path the page can reach. A value that can't be read as a TC string is removed only on the current host. Vendors that ask for the TC string get none until the visitor chooses in the CookieBeam banner.
So:
- Every TCF visitor is asked again after the switch. No bridge can avoid this.
- Don't try to copy the old
euconsent-v2value forward. CookieBeam won't use it.
Google Consent Mode
If your previous tool set the Consent Mode defaults, CookieBeam takes that over. Check that only one tool sets them, and that the CookieBeam loader still comes before your Google tags. See Google Consent Mode.
After the switch
- Follow Verify your installation on the live site.
- Check the load-order findings for tags that still run before CookieBeam.
- Remove leftovers from the previous tool: its script tag, its tag-manager triggers, and any code that read its cookie.
- If you used the bridge, test it with a browser that still has the previous tool's cookie. Confirm the banner closes and the consent record's
collectedViaisapi. - Remove the bridge once the previous tool's cookies have expired.