Closed alextremp closed 6 years ago
Hi,
Are you subscribed to cmpReady event?
You should use this way to listen to the event Boros is dispatching:
boroscmp.init()
window.document.addEventListener("cmpReady", (event) =>{
// call the command you want as follows...
window.__cmp('ping', null, (data, success) => {
console.log(JSON.stringify(success, null, 2));
console.log(JSON.stringify(data, null, 2));
})
})
`
Definitely we should create documentation about the two possible ways of knowing when BorosCmp is ready:
To initialize Boros CMP using default configuration values:
import boroscmp from '@schibstedspain/boros-cmp'
boroscmp.init()
.then(()=>{
// do your stuff ...
})
To initialize Boros CMP using customized configuration values:
import boroscmp from '@schibstedspain/boros-cmp'
const customConfig = {
gdpr: {
gdprApplies: true,
storeConsentGlobally: false
},
consent: {
consentScreen: 1,
consentLanguage: 'es'
}
}
boroscmp.init({config: customConfig})
.then(()=>{
// do your stuff ...
})
Notice that init method is returning a Promise but you can subscribe to cmpReady event instead:
import boroscmp from '@schibstedspain/boros-cmp'
boroscmp.init()
window.document.addEventListener("cmpReady", (event) =>{
// do your stuff ...
// like calling window.__cmp( ...
})
Solved in version -> @schibstedspain/boros-cmp@1.0.3
SUMMARY When the boros-cmp is imported and the init method is called it's expected to be able to use the window.__cmp function, but there's a race condition as the initialization runs in a Promise.
STEPS TO REPRODUCE
EXPECTED RESULT
ACTUAL RESULT