• Resolved mschmale

    (@mschmale)


    Hi,

    I’d like to use the ‘cmplzStatusChange’ event to trigger a custom script. Unfortunately, the value for event.detail.category isn’t correct.

    Could you please help me with this?

    
    document.addEventListener('cmplzStatusChange', function (event) {
     console.log(JSON.stringify(event.detail));
    });
    

    Thanks,
    Mark

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter mschmale

    (@mschmale)

    I think I have to use cmplzFireCategories instead.

    Plugin Contributor Rogier Lankhorst

    (@rogierlankhorst)

    You can remove the stringify function. It is not necessary.

    Plugin Contributor jarnovos

    (@jarnovos)

    Hi @mschmale,

    Have you been able to get this up and running already?

    Just let us know if we can provide any assistance with this!

    Kind regards,
    Jarno

    Thread Starter mschmale

    (@mschmale)

    Hi @jarnovos,

    Thanks for your reply and sorry for the late update.

    This is my solution right now. Not fancy, but I think it’s working. ??
    Would be nice though to know the reason why cmplzStatusChange is not working the way I think it should be.

    Regards,
    Mark

    (function ($) {
        $(function () {
    		let $cc_window;
    		const waitForCmplz = setInterval(function () {
    			$cc_window = $('#cc-window');
    			if ($cc_window.length > 0) {
    				clearInterval(waitForCmplz);
    				const $statistics = $cc_window.find('#cmplz_statistics');
    				$cc_window.find('.cc-save').on('click', function () {
    					if ($statistics.is(':checked')) {
    						_paq.push(['setConsentGiven']);
    						_paq.push(['rememberConsentGiven']);
    						_paq.push(['forgetUserOptOut']);
    						console.log('matomo optin');
    					} else {
    						if (!$('body').hasClass('cmplz-status-functional')) {
    							//_paq.push(['forgetConsentGiven']);
    							_paq.push(['optUserOut']);
    							console.log('matomo optout');
    						}
    					}
    				});
    			}
    		}, 10); // Wait for the input-field to appear
        });
    })(jQuery);
    
    document.addEventListener('cmplzRevoke', function () {
    	_paq.push(['optUserOut']);
    	console.log('matomo optout');
    });
    
    • This reply was modified 3 years, 4 months ago by mschmale.
    • This reply was modified 3 years, 4 months ago by mschmale.
    • This reply was modified 3 years, 4 months ago by mschmale.
    • This reply was modified 3 years, 4 months ago by mschmale.
    Thread Starter mschmale

    (@mschmale)

    What I am trying to do is to remove the consent for Matomo if a user revokes it. In the script center I’ve got this code:

    _paq.push(['setConsentGiven']);
    _paq.push(['rememberConsentGiven']);
    Thread Starter mschmale

    (@mschmale)

    Finally. I’ve got a working solution.

    document.addEventListener('DOMContentLoaded', function() {	
    	document.addEventListener('cmplzFireCategories', function (event) {
    		if (event.detail.category === 'statistics' || event.detail.category === 'marketing') {
    			_paq.push(['setConsentGiven']);
    			_paq.push(['rememberConsentGiven']);
    		} else {
    			_paq.push([function () {
    				if (this.isUserOptedOut()) {
    				} else {
    					_paq.push(['forgetConsentGiven']);
    				}
    			}]);
    		}
    	});
    });
    Plugin Contributor jarnovos

    (@jarnovos)

    Hi @mschmale,

    Glad to hear you got this up and running, thank you for confirming your solution.

    I’ll mark the thread as resolved for now, just let us know if you require any assistance with the plugin.

    Kind regards,
    Jarno

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘cmplzStatusChange not working properly’ is closed to new replies.