h5ai icon indicating copy to clipboard operation
h5ai copied to clipboard

How Can i add Adsense on H5Ai?

Open Dobob1022 opened this issue 7 years ago • 9 comments

i always check googl about adsense. but i can't find about adsense on H5AI. HELP ME Guys:0

Dobob1022 avatar Feb 22 '18 13:02 Dobob1022

Custom Header/Footer is the easiest way. Ref #654

Armstrong1992 avatar Feb 23 '18 09:02 Armstrong1992

just add raw adsense code in to header?

Dobob1022 avatar Feb 23 '18 09:02 Dobob1022

Or footer, yes. See https://github.com/lrsjng/h5ai/blob/44e53ab213d37f45df2acac01e957c67ec06f8a7/src/_h5ai/private/conf/options.json#L104-L111

Armstrong1992 avatar Feb 23 '18 10:02 Armstrong1992

Hmm I just add my code in _h5ai.header.html. but still i can't see any ad on my site! `

Dobob's Public Server.

public download server! :)

Just Click the File and you can download the file!

`

Here my page source. can you correct my code? i can see the ad on _h5ai.header.html but i can't see on H5AI. https://down.dobobwiki.com

Dobob1022 avatar Feb 23 '18 12:02 Dobob1022

It's harder than i thought. You will need to edit source files!

  1. Create file in public/js/lib/ext/google-ads.js: (change ca-pub to your ca-pub key)
const {dom, awaitLoad} = require('../util');
const event = require('../core/event');
const allsettings = require('../core/settings');

const win = global.window;
const settings = Object.assign({}, {});

const init = () => {

        const script = '<ins class="adsbygoogle"\n' +
            '     style="display:block"\n' +
            '     data-ad-client="ca-pub-XXXXXXXXX"\n' +
            '     data-ad-slot="6586687715"\n' +
            '     data-ad-format="auto"></ins>\n';
        dom(script).preTo('body');
        (adsbygoogle = win.adsbygoogle || []).push({});

};
init();
  1. Edit public/js/lib/main/index.js and add:
require('../ext/google-ads');
  1. Edit private/php/pages/page.tpl.pug and add (line 18 after script(src!='...):
script(src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js")
  1. Build npm run build

It's just proof of concept, so feel free to modify as you need.

Armstrong1992 avatar Feb 26 '18 09:02 Armstrong1992

Since the code is updated, maybe I cannot find where is "private/php/pages/page.tpl.pug". I follow the instruction in "_h5ai/private/conf/options.json" `/* Resources.

Additional script and style tags added to all pages. Paths not beginning
with "http://", "https://" or "/" will be looked up relative to
"_h5ai/public/ext/" (no check for existence).

- scripts: array of strings
- styles: array of strings
*/`

and indicate my js file directory, but Google Adsense cannot work. What else should I do?

sutdorg avatar Dec 02 '18 01:12 sutdorg

I added a-ads to my site, however, it was very troublesome, and with fastBrowsing enabled, The ad does not refresh which causes the user to count as 1 view, despite them browsing and opening different pages

GovetaXV avatar Mar 24 '19 22:03 GovetaXV

Is there a way that doesn't involve editing source? Especially as I don't use adsense the above example won't work

androidacy-user avatar Oct 04 '20 02:10 androidacy-user

I use AdSterra

androidacy-user avatar Oct 04 '20 02:10 androidacy-user