Extension talk:WimaAdvertising

About this board

pagead2.googlesyndication.com

4
Summary by WikiForMen

Issue is solved.

Redundant-decadence (talkcontribs)

I do not want to use the extension for Google Ads, just for my own content. However, there is a call to pagead2.googlesyndication.com. Luckily, this is prevented by my CSP settings:

Refused to load the script 'https://pagead2.googlesyndication.com/pagead/show_ads.js' because it violates the following Content Security Policy directive: "script-src 'unsafe-eval' blob: 'self' 'unsafe-inline'". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.

For privacy reasons, I do not want any calls to Google servers, or any other 3rd-party requests, except those I selected carefully. Can I prevent this with configuration settings? This is my current configuration:

wfLoadExtension( 'WimaAdvertising' );

$wmWimaAdvertising = true; $wmWimaAdvertisingAnonOnly = false; $wmSidebarAd1Type = "advertising"; $wmSidebarAd1Code = '<a href="https://www.7gutegruende.de/planspiel-hvr/"><img src="https://roter-kreis.de/images/f/fd/7GG-e069-2023-12-23-Planspiel-HVR_500.png" alt="Spielst du noch oder lernst du schon? Planspiel zum humanitären Völkerrecht" /></a>';

$wmSidebarAd1Style = ;

$wmGoogleAdSense is false (by default). Setting it to false does not change anything.

Any idea?

WikiForMen (talkcontribs)

The problem is that $wmGoogleAdSenseSrc is set per default to //pagead2.googlesyndication.com/pagead/show_ads.js

Solution: Set $wmGoogleAdSenseSrc to an empty string and the issue should have gone.

Redundant-decadence (talkcontribs)

Great! This solved my problem. Thank you!

WikiForMen (talkcontribs)

I have fixed the issue. Now it is ensured that the variable $wmGoogleAdSense is set to true before the script $wmGoogleAdSenseSrc is included.

Redundant-decadence (talkcontribs)

I suggest to add an additional BannerType: 'recommendation'.

WikiForMen (talkcontribs)

'Hint' or 'recommendation' is basically the same thing, the choice of words depends on personal preference. You can of course customise the extension by changing the corresponding entry in the i18n/en.json file.

I have just added the BannerType 'blank' in version 2.6.0.

Redundant-decadence (talkcontribs)

Thank you, very much.

WikiForMen (talkcontribs)

Merry Christmas!

Problems with Sidebar on Vector w/ MediaWiki 1.36.1

3
Summary by WikiForMen

Issue should be resolved with version 2.3.0.

2601:182:CA02:94A0:990C:DF16:18FD:42E9 (talkcontribs)

Hi everyone,

I'm encountering a problem getting Wima Advertising to function in the AD1 and AD2 sidebar slots on the Vector skin included with MediaWiki 1.36.1. I attempted to apply the patch specified for Vector in 1.35, but the file located at "includes/VectorTemplate.php" no longer exists. Please update the page with instructions for 1.36.1, thanks!

WikiForMen (talkcontribs)
WikiForMen (talkcontribs)

No Adsense code added to MediaWiki

25
Summary by WikiForMen

An issue with skin Timeless has been resolved in version 2.4.1.

Costas Athan (talkcontribs)

Here is the code I have added to LocalSettings.php:

wfLoadExtension( 'WimaAdvertising' );

$wmGoogleAdSense = true;
$wmGoogleAdSenseClient = 'ca-pub-xxxxxxxxxxxxxxx';
$wmGoogleAdSense_AD1 = [ '<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-xxxxxxxxxxxxxxx" crossorigin="anonymous"></script>
<ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-xxxxxxxxxxxxxxx"
data-ad-slot="xxxxxxxxxx" data-ad-format="auto"  data-full-width-responsive="true">
</ins>
<script>(adsbygoogle = window.adsbygoogle || []).push({});</script>', 145, 260 ];
$wmGoogleAdSenseSrc = '//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-xxxxxxxxxxxxxx';

This has as a result no ad related code do be added anywhere in the HTML source.

I have also tried instead of setting $wmGoogleAdSense_AD1 to use Manual:Hooks/SkinAfterPortlet. Here is the relative code:

$wgHooks['SkinAfterPortlet'][] = function($skin, $portletName, &$html) {$user = $skin->getUser();
if ($portletName === "tb") {
$html = <<< EOT
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-xxxxxxxxxxxxxxxx" crossorigin="anonymous"></script>
<ins class="adsbygoogle"
    style="display:block"
    data-ad-client="ca-pub-xxxxxxxxxxxxxxxx"
    data-ad-slot="xxxxxxxxxx"
    data-ad-format="auto"
    data-full-width-responsive="true"></ins>
<script>(adsbygoogle = window.adsbygoogle || []).push({});</script>
EOT;
return true;
}
};

The addition of the hook reserves a space under the "Wiki Tools" section, but again no ads shown. I'm not sure if this has to do with AdSense itself though.

And just a final question. Shouldn't any AdSense code be added by the extension in the <header>? Now the only code added is the one by the SkinAfterPortlet hook. Shouldn't setting the $wmGoogleAdSenseSrc variable lead to an addition of related code in the header section?

WikiForMen (talkcontribs)
WikiForMen (talkcontribs)

Regarding to your question about AdSense code in the <header>: This job is done by the HeaderExtension. But I'm afraid that doesn't place adverts in the sidebar.

Costas Athan (talkcontribs)

If I'm not mistaken Google suggests to add the code which you assign to the $wmWimaGoogleAdSenseSrcvariable in the header section of the HTML. Maybe you should modify the WimaAdvertising extension to do just that, add that specific line of code in the header.

WikiForMen (talkcontribs)
Costas Athan (talkcontribs)

I tried to use your other Extension, HeaderExtension, for this particular reason, but I again got an error. I have started a topic in the discussion of HeaderExtension about it.

WikiForMen (talkcontribs)

OK, it is $wmGoogleAdSenseSrc not $wmWimaGoogleAdSenseSrc. I fixed this in the description. But the main problem is that the skin Timeless does not display adverts in the sidebar, while other skins do. I have just tested this and I asked you to do the same to rule out misconfigurations.

At the moment, placing $wmGoogleAdSenseSrc in the <head> section will not solve our problem. However, I will make a note of your suggestion for a later version.

Costas Athan (talkcontribs)

I know it won't solve the problem. I'm just pointing it out, that Google suggests this particular script to be placed within the header.

Well, I just tried MonoBook and Vector skins, without luck. Still no ad code added in the HTML. Note that this time I have already added * AD1 in the MediaWiki:Sidebar.

Are you sure the rest of the variables ($wmWimaGoogleAdSense, $wmWimaGoogleAdSenseClient, $wmWimaGoogleAdSense_AD1) are named correctly ?

WikiForMen (talkcontribs)

No, all $wmWimaGoogle… should be $wmGoogle….

Costas Athan (talkcontribs)

@WikiForMen

OK. I renamed all those variables I mentioned in my previous message and it seems that things work now, with the exception of Timeless skin. You should update their names in the Wiki.

Can this line of code

WikiForMen (talkcontribs)
Costas Athan (talkcontribs)

I hadn't. I just added it, then cleared Cloudflare cache, but it made no difference.

$wmGoogleAdSense_AD1= [ 'xxxxxxxxxx', 145, 260 ];

I tried both Fixed and Responsive ads, but also that made no difference.

The SkinAfterPortlet is probably working. I see the space reserved and the code injected in the HTML. I guess that another unrelated issue is preventing the ads from showing in the hook's case.

But is there a reason to use WimaAdvertising extension along with the hook?

WikiForMen (talkcontribs)

I developed WimaAdvertising before REL1_35, the hook SkinAfterPortlet was introduced with REL1_35. Due to changes in REL1_39 injecting HTML with the SkinBuildSidebar hook. I was told that as of REL1_35 the SkinAfterPortlet hook should do the job. And it works fine, but not for the Timeless skin. :-(

That's why I asked on the Timeless talk page what this is all about.

But I would ask you to switch to other skins - you can easily do that under your personal settings - and watch the sidebar under other skins to prevent misconfigurations.


The special reason to use WimaAdvertising is that you can fix css issues in the sidebar by editing the corresponding resources.

The extension SkinCustomiser, for example, allows you to customise standard skins. You may want to define a border or background colour for the sidebar blocks. However, this should not appear for the advertising banner blocks; this is done - among other things, such as the placement between the blocks (see * AD1, * AD2) - by the WimaAdvertising extension.

WikiForMen (talkcontribs)

I am still debugging. For now I figured out, that the hook SkinAfterPortlet is supported for skin Timeless. This is actually clear, because other extensions such as extension DonateButton also work in the same way and appear normally in Timeless. But I was initially confused due to the lack of explanations.

But for some reason all skins are fine with

* AD1

in MediaWiki:Sidebar.

For some reason I do not understand until now is, why skin Timeless works with

* AD1
**item_url|item

in MediaWiki:Sidebar.

The thing with AD1 and AD2 is a bit tricky, because these are placeholders for something that can be an advert, an event or a notice through individual configuration, which should also be translatable into different languages. It took me a lot of fiddling around until it finally worked as intended.

The good news for today is that WimaAdvertising basically also works for Skin Timeless. :-)

Now I just have to find out why Skin Timeless doesn't show the adverts when the list after AD1 or AD2 is empty.

WikiForMen (talkcontribs)

Now I understand what I also made a dirty hack for the DonateButton extension to make the Hook SkinAfterPortlet work for the Timeless skin.

So Timeless has a problem with Hook SkinAfterPortlet when the portlet is empty, that is, it contains no elements.

In GitHube I uploaded a new Version 2.4.1 that fixed it.

Costas Athan (talkcontribs)

Are you sure it works? I just installed version 2.4.1 and it still doesn't seem to work for me.

Here is my code:

$wmGoogleAdSense = true;
$wmGoogleAdSenseClient = 'ca-pub-XXXXXXXXXXXXXXXXX';
$wmSidebarAd1Type = "advertising";
$wmSidebarAd1Code = '<script>/* Adsense script */</script>';

When I assign the same Adsense script to: $wgHooks['SkinAfterPortlet'][] ads appear without an issue.

WikiForMen (talkcontribs)

$wmSidebarAd1Code is for the none Google AdSense.

In your case it should be:

$wmGoogleAdSense_AD1 = [ 'slot #', 145, 260 ];
$wmGoogleAdSenseClient = 'ca-pub-XXXXXXXXXXXXXXXXX';
$wmGoogleAdSenseID = 'ID-XXX';
$wmGoogleAdSenseSrc = '<script>/* Adsense script */</script>'

Now I will upload Version 2.5.0.

Costas Athan (talkcontribs)

Extension:WimaAdvertising#wgBannerCode You assign the AdSense script to $wmSidebarAd2Code. Is this possible only for AD2? Not for Ad1? That's confusing. I expected both AD1 and AD2 to have the same functionality.

By the way, is it possible to utilize responsive ads with this extension? As I see in the code hereː $wmGoogleAdSense_AD1= [ 'xxxxxxxxxx', 145, 260 ]; you have to mention width and height properties.

WikiForMen (talkcontribs)

Look at the documentation. You can define up to four ad units.

Example:

$wmGoogleAdSense_AD2 = [ 'slotid', width, height ];

I have added a new subheading in the documentation to make it clear that the section "Wima web slots" is not relevant for "Google Adsense" slots.

The thing with the "Wima web slots" is that there is no "Google Adsense" that provides the advertising data, there you can set your individual code to advertise a book or an event, for example. But that's not what you want. The WimaAdvertising extension offers both options. Originally, WimaAdvertising could only do the individual variant because it was what I needed. Later, I integrated the option "Google Adsense" because I assumed that there was a need for it. Of course, you then have to skip the settings for "Wima web slots".

Costas Athan (talkcontribs)

What about "Responsive" ads. Are they supported or only "Fixed" sized ones?

By the way on the "Wima web slots section" you have this codeː

$wmSidebarAd2Code = '<script type="text/javascript">
google_ad_client = "ca-pub-xxxxxxxxxxxxxxx";
google_ad_slot = "3512091103";
google_ad_width = 145;
google_ad_height = 260;
google_language = "en";
google_encoding = "utf8";
</script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js&amp;amp;amp;#x22;&amp;amp;amp;#x3E;&amp;amp;amp;#x3C;/script>';

which is an example of an AdSense script.

WikiForMen (talkcontribs)

And yes, in the "Wima web slots section" you find an example how you can do "Google AdSense" also on the "Wima web slot" way. :-)

But you have to decide for on way and follow it consistently.

WikiForMen (talkcontribs)
Costas Athan (talkcontribs)

OKǃ

Look my edit of my previous post about $wmSidebarAd2 code in "Wima web slots" section. You may want to edit this example.

WikiForMen (talkcontribs)

I have tried this

$wmWimaAdvertising = true;
$wmGoogleAdSense = false;
$wmSidebarAd1Code = '<script type="text/javascript">
google_ad_client = "ca-pub-xxxxxxxxxxxxxxx";
google_ad_slot = "3512091103";
google_ad_width = 145;
google_ad_height = 260;
google_language = "en";
google_encoding = "utf8";
</script>';
$wmGoogleAdSenseSrc = 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-xxxxxxxxxxxxxx';

and it seems to work!

But this should do the same:

$wmWimaAdvertising = false;
$wmGoogleAdSense = true;
$wmGoogleAdSenseClient = 'ca-pub-xxxxxxxxxxxxxxx';
$wmGoogleAdSense_AD1 = [ '3512091103', 145, 260 ];
$wmGoogleAdSenseSrc = 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js';
WikiForMen (talkcontribs)

New in 2.5.0

  • Place JavaScript for GoogleAdSense in `<head>` section.

Just as you suggested.

There are no older topics