To turn on the “Subscribe with Google” feature for your publication, you must configure each page on your site with a code snippet the Google Publisher Center generates. This snippet:
- Loads the Subscribe and Contribute features
- Associates your pages with one or many pricing plans
To install the snippet, you must have permission to access and edit your site’s theme or template code in your content management system (CMS).
Add a code snippet to your site
- Go to Google Publisher Center.
- Sign in with a Google Account you use with your publication.
- Select a publication you have with a subscription or contribution plan turned on. Make sure you have an active pricing plan.
- Click Subscribe with Google.
- Under “Quick Links,” select CMS Sync. Under the “CMS Sync” tab in the Publisher Center, you can find:
- Open access snippets
- To give readers open access to all content, add this code snippet to the specific content in your Content Management System.
- Product ID snippets
- On the pages you want to prevent access to users without a subscription, copy the product ID snippet you want to use.
- Open access snippets
- Add the snippet to the
<head>
tag of each page you want to turn “Subscribe with Google” on. - To make sure “Subscribe with Google” loads properly, go to your website.
Tips:
- If you make a change to your pricing with a new product ID, you must update your CMS Sync on your website.
- If you have multiple plans active on a single site, you must configure multiple snippets:
- Configure one snippet for each product ID.
- Include these product IDs on the:
- Relevant pages
- Templates within your CMS
Glossary
Fields
alwaysShowThe alwaysShow
attribute accepts a boolean true
or false
.
- When this value is set to
true
: The prompt always displays. This prompt overrides your frequency settings in the Google Publisher Center - The default value is
false
.
- For contributions: set
autoPromptType
tocontribution
. - For subscriptions: set
autoPromptType
tosubscription
.
- If you don’t want the prompt to automatically display when the page loads, set
autoPromptType
tonone
.
The clientOptions
attribute accepts an Object where you can specify theme and language. If you don’t specify a language value, it defaults to your Publisher Center settings. Language codes for this attribute follow ISO 639-1 format.
- For theme: Specify “light” or “dark.”
- For
lang
: Specify the language code, such as “en.”
The isAccessibleForFree
attribute determines whether the subscription or contribution prompts are:
- Dismissible
- Not dismissible
- To set the prompts as optional, set
isAccessibleForFree
totrue
. - To set the prompts as required, set
isAccessibleForFree
tofalse
.
To specify the pricing plan you want to configure for your page, use the isPartofProductID
attribute. This attribute follows the syntax of <PUBLICATION_ID>:<PRODUCT_ID>
. Your get its product ID from the Google Publisher Center.
To make sure the snippet loads correctly on the page, set the pricing plan to “live.”
The isPartOfType
attribute accepts an array of strings. When you copy the code snippet, the default value for this attribute is set to ["Product"]
.
The type property should fall in line with structured data markup schema. For news publications, use NewsArticle
— more information is available on Schema.org.
Example code snippet
JavaScript
<script async type="application/javascript"
src="https://news.google.com/swg/js/v1/swg-basic.js"></script>
<script>
(self.SWG_BASIC = self.SWG_BASIC || []).push( basicContributions => {
basicContributions.init({
type: "NewsArticle",
isAccessibleForFree: true,
isPartOfType: ["Product"],
isPartOfProductId: "<PUBLICATION_ID>:<PRODUCT_ID>",
alwaysShow: true,
autoPromptType: "contribution_large",
clientOptions: { theme: "light", lang: "en" },
});
});
</script>