There are two methods of showing Subscribe with Google button on your website.
Smart Button renders the button with a contextual message underneath the button.
Read the documentation.
<button>
DOM element in your page where you want the Subscribe with Google button to appear.attachButton()
function from swg.js
to render a standard button.<html>
<head>
<!-- 1. Configure swg.js ... -->
<script async type="application/javascript"
src="https://news.google.com/swg/js/v1/swg.js"></script>
<script>
(self.SWG = self.SWG || []).push( subscriptions => {
// 3. Render the smart button onto the DOM element
let swgStdButton = document.getElementById("swg-standard-button");
subscriptions.attachButton(
swgStdButton,
// 4. Include options i.e. light styles or languages..
{theme: 'light', lang: 'en'},
// .. and onclick functions in the callback i.e. showOffersor subscribe(SKU)
function() {
subscriptions.showOffers({ isClosable: true }) // Show offers carousel
});
});
</script>
</head>
<body>
<!-- 2. Add the button DOM element -->
<button id="swg-standard-button"></button>
<!-- ...include structured markup data in step 1. -->
<script type="application/ld+json">{....}</script>
</body>
</html>
<button>
DOM element in your page where you want the Subscribe with Google button to appear.attachSmartButton()
function from swg.js
to render the smart button.<html>
<head>
<!-- 1. Add swg.js ... -->
<script async type="application/javascript"
src="https://news.google.com/swg/js/v1/swg.js"></script>
<script>
(self.SWG = self.SWG || []).push( subscriptions => {
// 3. Render the smart button onto the DOM element
let swgSmartButton = document.getElementById("swg-smart-button");
subscriptions.attachSmartButton(
swgSmartButton,
// 4. Include options i.e. light styles or languages..
{theme: 'light', lang: 'en'},
// .. and onclick functions in the callback i.e. showOffersor subscribe(SKU)
function() {
subscriptions.showOffers({ isClosable: true }) // Show offers carousel
});
});
</script>
</head>
<body>
<!-- 2. Add the button DOM element -->
<button id="swg-smart-button"></button>
<!-- ...include structured markup data in step 1. -->
<script type="application/ld+json">{....}</script>
</body>
</html>