Douyacun

react接入google广告: 支持服务端渲染

原创:react2021/01/18发布pv:0uv:0ip:0twitter #react

原文地址:https://www.douyacun.com/article/43284034aeede40846638a36caa18592

@hustcc react-adsense 不支持服务端渲染框架,受 react-adsense 启发写了 react-ssr-adsense

react-ssr-adsense

react-ssr-adsense is a React-ssr-component for Google AdSense。support #nextjs

npm npm npm

1. Install

npm install --save react-ssr-adsense

Before use Google AdSense, you should add the script at the end of HTML.

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>

2. Usage

import React from 'react';
import AdSense from 'react-ssr-adsense';

// ads with no set-up
<AdSense
  client='ca-pub-7292810486004926'
  slot='7806394673'
/>

// ads with custom format
<AdSense
  client='ca-pub-7292810486004926'
  slot='7806394673'
  style={{ width: 500, height: 300, float: 'left' }}
  format=''
/>

// responsive and native ads
<AdSense
  client='ca-pub-7292810486004926'
  slot='7806394673'
  style={{ display: 'block' }}
  layout='in-article'
  format='fluid'
/>

// auto full width responsive ads
<AdSense
  client='ca-pub-7292810486004926'
  slot='7806394673'
  style={{ display: 'block' }}
  format='auto'
  responsive='true'
  layoutKey='-gw-1+2a-9x+5c'
/>

3. Props

  • Required props:
    • client
    • slot
  • Optional props:
    • className:
    • style:
    • layout:
    • layoutKey:
    • format:
    • responsive:

LICENSE

MIT@douyacun.

相关推荐

  • 深入浅出React和Redux
  • React进阶之路
  • react服务端渲染: cookie如何透传给后端,后端如何设置cookie
  • react 移动边框
  • react服务端渲染: markdown
  • npm publish: react component/react hook component
  • D