Skip to content

Latest commit

 

History

History
76 lines (54 loc) · 2.29 KB

embed-client.md

File metadata and controls

76 lines (54 loc) · 2.29 KB

Include SwG client on a site

Including SwG client script

The SwG client is available as a JavaScript library distributed at this URL:

https://news.google.com/swg/js/v1/swg.js

To include the SwG client on a page, include a <script> tag as follows (notice the async attribute):

<script async src="https://news.google.com/swg/js/v1/swg.js"></script>

Client ready callback

To get a callback when SwG client is ready, use the following code:

(self.SWG = self.SWG || []).push(function(subscriptions) {
  // SwG is ready to be called via subscriptions interface.
});

This callback provides a subscriptions object. See Subscriptions API for more details.

Client initialization

Before SwG client can be used it must be initialized. There are two ways to initialize the client: auto and manual.

Auto-initialization

SwG client can initialize itself automatically when Subscriptions markup is present on the page. By default the SwG client will attempt to auto-initialize. This is the recommended method for content pages (articles).

Manual initialization

To initialize the client manually, first set the subscriptions-control="manual" flag on the script:

<script async subscriptions-control="manual" src="https://news.google.com/swg/js/v1/swg.js"></script>

Then initialize using the API:

(self.SWG = self.SWG || []).push(function(subscriptions) {
  // Either use a publication ID (example.com) or
  // a full product ID (example.com:premium).
  // Note: a wildcard product ID (example.com:*) will match any
  // entitlement for the publication
  subscriptions.init(publicationOrProductId);
});