klaro-org / klaro-js

Klaro Privacy Manager. An open-source, privacy-friendly & compliant consent manager for your website.
https://klaro.org
Other
1.19k stars 254 forks source link

TypeError: googletag.pubads is not a function in google tag #167

Closed sumiahTR closed 4 years ago

sumiahTR commented 4 years ago

Steps to reproduce

Current behavior

Expected behavior

adewes commented 4 years ago

Please provide the necessary information.

sumiahTR commented 4 years ago

Hii,

Sorry for the delayed response.

I have a google tag script.I added the klaro script to it.But it doesnt shows even when I accept the consant modal.

The google tags are loaded twice.

My first script is as:

script async='async' type="opt-in" data-type="application/javascript" data-name="googletag" data-src='https://www.googletagservices.com/tag/js/gpt.js'>

And the second script is as: When i try to run these it shows 'googletag.pubads is not a function' in the console. Please help.
adewes commented 4 years ago

What does your Klaro config look like? Do you define an entry for the googletag script?

sumiahTR commented 4 years ago

yeah I do.My config.js file looks like { name: 'googletag', default: true, title: 'Google Tag', purposes: ['advertising'], cookies: [ [/^pk.$/, '/', 'www.googletagservices.com'], //for the production version [/^pk.$/, '/', 'localhost'], //for the local version ], callback: function(consent, app) { // This is an example callback function. console.log(consent); console.log( 'User consent for app ' + app.name + ': consent=' + consent ); if(consent === true) { / var obj = $(this); console.log(obj); / } }, required: false, optOut: false, onlyOnce: false, },

adewes commented 4 years ago

The async option for your first script is the problem, I think. It causes that script to be loaded asynchronously in the background, while the two other scripts will be executed immediately, which is why pubads is not available to them. You should either remove async from the first script or use defer for all scripts, which will also defer the loading and maintain the execution order between the scripts, which async does not do.

sumiahTR commented 4 years ago

Thanks for the reply. The 'definePassback' of googletag was the problem.That doesnt work sometimes or misbehaviours. so i rewrote it to another script. Thanks.:)