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>
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.
Before SwG client can be used it must be initialized. There are two ways to initialize the client: auto and manual.
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).
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);
});