Conditional Content

hiding google adsense code for a user group possible?

2 years 3 months ago #69567

Christian Rieger's Avatar Christian Rieger

Hi!

Is it possible to hide the google adsense javascript code for a user group, maybe in combination with sourcerer? The aim is to show advertising in content only for guests (non-subscribers).

{hide usergrouplevels!="my_user_group"}adsense code{/hide}
or
{hide usergrouplevels!="my_user_group"}{source}adsense code{/source}{/hide}

I tried both by copying in my templates head.php without success.

Many thanks in advance!

Christian

2 years 3 months ago #69572

Peter van Westen's Avatar Peter van Westen Admin

Try using the editor button in an articles to get the correct syntax. The copy that to wherever you have that code.

You don't need Sourcerer if you are placing code in a php file. You can just place the code right in there.

2 years 3 months ago #69588

Christian Rieger's Avatar Christian Rieger

Yes I tried with the editor. but adsense isn't running and conditions don't work.
Thats the code I'm using:

{hide matching_method="any" usergrouplevels="Einzellizenz,Testlizenz" templates="buildr--39,buildr--43,buildr--44"}<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script>
  (adsbygoogle = window.adsbygoogle || []).push({
    google_ad_client: "ca-pub-2439512335750602",
    enable_page_level_ads: true
  });
</script>{/hide}

Just gives me the line
{hide matching_method="any" usergrouplevels="Einzellizenz,Testlizenz" templates="buildr--39,buildr--43,buildr--44"}{/hide}
on each page.

2 years 3 months ago #69595

Peter van Westen's Avatar Peter van Westen Admin

The idea behind Conditional Content is that you use it in Joomla content (articles, modules, etc).
Your template is probably not passing that head.php through the Joomla plugins.

Can't you just place the code in a Custom (HTML) module and assign that module to the usergroups you want?
(You can use Advanced Module Manager and Sourcerer to do this).

2 years 3 months ago #69638

Christian Rieger's Avatar Christian Rieger

Yes, this way with Advanced Module Manager and Sourcerer works perfect.
Thank a lot!

2 years 3 months ago #69639

Peter van Westen's Avatar Peter van Westen Admin

Nice 🙂