Vanilla JS

The tiun SDK can be loaded directly in a browser using a module script tag — no build tools needed. Import from unpkg (or any CDN that serves the package).


Initialize

Load the SDK as an ES module and call init().

<script type="module">
  import { tiun } from 'https://unpkg.com/@tiun/sdk/tiun.js';

  tiun.init({
    snippetId: 'YOUR_SNIPPET_ID',
    language: 'en', // set to your site's language
  });
</script>

Checkout

Attach checkout to a button click.

<button id="btn-checkout">Subscribe</button>

<script type="module">
  import { tiun } from 'https://unpkg.com/@tiun/sdk/tiun.js';

  tiun.init({ snippetId: 'YOUR_SNIPPET_ID', language: 'en' });

  document.getElementById('btn-checkout').onclick = () => {
    tiun.checkout({ productId: 'YOUR_PRODUCT_ID' });
  };
</script>

Listen for user changes

Update the page when authentication or access changes.


Login and logout


Gate content

Show or hide elements based on productAccess.


Read properties

Check SDK state at any point using properties.


Paywall events (time-based)

For time-based billing, use paywall events to show or hide content.

Last updated

Was this helpful?