How to embed Google Ad Sense into React Component?

后端 未结 3 1193
栀梦
栀梦 2020-12-09 00:13

The question at hand deals with Google Ad Sense specifically but could apply to any script tag insert. I don\'t understand how I could add something like this to my compon

3条回答
  •  忘掉有多难
    2020-12-09 01:05

    Maybe you can use this react-component: react-adsence. It supports both Google and Baidu.

    Google AdSence gives you the ad code below:

    
    
    
    
    

    So how to include it in a react component? Very easy:

    1. Write a Component Class, and give it props with style, client, slot, format.
    2. exec (adsbygoogle = window.adsbygoogle || []).push({}); in the componentDidMount lifecycle method.

    Then get the react-adsence. How to use it?

    import AdSence from 'react-adsence';
    
    
    

    Before doing this, you should add the script in the HTML.

    
    

    Notice: modify the client/slot with yours.

提交回复
热议问题