Learn about code snippet properties

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

  1. Go to Google Publisher Center.
  2. Sign in with a Google Account you use with your publication.
  3. Select a publication you have with a subscription or contribution plan turned on. Make sure you have an active pricing plan.
  4. Click Subscribe with Google.
  5. 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.
  6. Add the snippet to the <head> tag of each page you want to turn “Subscribe with Google” on.
  7. 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

alwaysShow

The 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.
autoPromptType
  • For contributions: set autoPromptType to contribution.
  • For subscriptions: set autoPromptType to subscription.
  • If you don’t want the prompt to automatically display when the page loads, set autoPromptType to none.
clientOptions

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.”
Example: {theme: 'dark', lang: 'en'}
isAccessibleForFree

The isAccessibleForFree attribute determines whether the subscription or contribution prompts are:

  • Dismissible
  • Not dismissible
If the prompt is optional, at the top right, a small will appear.
  • To set the prompts as optional, set isAccessibleForFree to true.
  • To set the prompts as required, set isAccessibleForFree to false.
isPartOfProductID

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.”

isPartOfType

The isPartOfType attribute accepts an array of strings. When you copy the code snippet, the default value for this attribute is set to ["Product"].

type

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>
Was this helpful?
How can we improve it?
Search
Clear search
Close search
Google apps
Main menu
Search Help Center
true
true
false
true
true
100499
false
false