• Hello.

    I have the feeling that this plugin does not work perfectly in a certain casuistry. I understand that it may not be your problem but I ask if, from the plugin, there is a solution.

    I have my website hosted on Siteground.
    Siteground has a dynamic caching system that avoids the PHP request if you have the page cached on your system: https://www.siteground.com/kb/siteground-dynamic-caching-configuration/

    This does not seem to be affected if trackings, for example Google Analytics, are put in the GDPR Cookie Compliance section > Settings > Analytics cookies (head) (third party).

    My problem is that I use the Hotjar script only in certain URLs as I asked here: https://ww.wp.xz.cn/support/topic/can-cookies-be-added-to-specific-pages/

    It seems that the code in functions.php works “sometimes”.

    I can’t get it to run every time and I imagine it has to do with this Dynamic Cache option that always serves “the first hit it has from the requested page and this first HIT, unfortunately, it does not have the cookies activated”.

    I don’t know why, if I put the javascript code in the plugin section so that it is painted on all the pages “it does work”, but if I do it through functions.php it doesn’t.

    I imagine that, through your plugin, there is some ajax or javascript type code that writes the code entered in the “analytics” section.

    Can you help me do some research on this?
    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Moove Agency

    (@mooveagency)

    Hi @ciltocruz,

    Thanks for using our plugins.

    If the PHP cookie checker is not working because of server caching, you can try to use the JavaScript extension, like this:

    add_filter('gdpr_cookie_script_cache', '__return_empty_array' );
    add_action('moove_gdpr_third_party_header_assets', function( $scripts ) {
    	?>
    	<script>
    		var pages_to_insert = [
    		'/checkout', // checkout page
    		'/cart', 		 // cart page
    		'/', 				 // homepage
    		];
    
    		var current_path = window.location.pathname;
    		// removing the last slash form path if exists
    		current_path = (current_path.substr(-1) === '/') && current_path.length > 1 ? current_path.substr(0, current_path.length - 1) : current_path;
    
    		// checking if the scripts should be inserted based on current page path
    		if ( Object.values(pages_to_insert).indexOf(current_path) > -1 ) {
    			console.warn('hotjar inserted');
    			// INSERT TRACKING SCRIPT HERE
    			...
    	  }
    	</script>
    	<?php
    	return $scripts;
    });

    This might require some development knowledge to implement, you can speak to your developers to implement the solution for you.
    There is a pages_to_insert variable where the page slugs should be defined where you would like to insert your tracking script.

    Hope this helps.

    Thread Starter Marcos Muñoz Iglesias

    (@ciltocruz)

    Should I add this in the functions.php?

    Plugin Author Moove Agency

    (@mooveagency)

    Hi @ciltocruz

    Yes, please include that script in your functions.php, however the code will not work out of the box.

    There is the pages_to_insert variable that need to be defined first, plus you need to insert the tracking scripts to the right place.

    Hope this helps.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Siteground Dynamic Cache’ is closed to new replies.