Skip to main content

Configuration

All configuration is passed to ContentCredits.init() as a plain JavaScript object.

ContentCredits.init({
// Required
apiKey: 'pub_YOUR_API_KEY',

// Core options
contentSelector: '#premium-content',
teaserParagraphs: 2,
enableComments: true,
articleUrl: window.location.href,
theme: {
primaryColor: '#44C678',
fontFamily: 'Georgia, serif',
},
debug: false,

// Headless mode (no built-in UI)
headless: false,

// Callbacks
onAccessGranted: () => { },
onStateChange: (state) => { },
onLoginRequired: () => { },
onPurchaseRequired: ({ requiredCredits, creditBalance }) => { },
onInsufficientCredits: ({ required, available }) => { },
onPurchased: ({ creditsSpent, remainingBalance }) => { },
onUserLogin: (user) => { },
onUserLogout: () => { },
onError: ({ message }) => { },
onReady: (state) => { },
});

Core options

OptionTypeDefaultDescription
apiKeystringRequired. Publisher API key (pub_...)
contentSelectorstring'.cc-premium-content'CSS selector for the element to gate
teaserParagraphsnumber2Visible paragraphs before the paywall
enableCommentsbooleantrueShow the comment widget
articleUrlstringwindow.location.hrefCanonical URL for the article
theme.primaryColorstring'#44C678'Brand colour for buttons and accents
theme.fontFamilystringSystem UIFont for all SDK text
paywallTemplatestringCustom HTML for the paywall overlay
extensionIdstringBuilt-in IDOverride the Chrome extension ID
debugbooleanfalseVerbose console logging

Headless mode

Set headless: true to disable all built-in DOM manipulation and UI rendering. The SDK becomes a pure logic layer — it runs the access check, manages auth, and fires callbacks, but never hides content or injects UI.

ContentCredits.init({
apiKey: 'pub_YOUR_KEY',
headless: true,
onLoginRequired() { /* show your login UI */ },
onPurchaseRequired({ requiredCredits }) { /* show your unlock UI */ },
onAccessGranted() { /* reveal your content */ },
});

See the Headless mode guide for complete examples.


Callbacks

Callbacks fire in both default and headless mode. In headless mode they are your only UI triggers — the built-in overlay never appears.

CallbackFires when
onAccessGranted()Access confirmed (existing or just purchased)
onStateChange(state)Any state field changes — use for reactive UI
onReady(state)First access check complete
onLoginRequired()Paywall hit, user not logged in
onPurchaseRequired({ requiredCredits, creditBalance })Logged in, article not purchased
onInsufficientCredits({ required, available })Balance too low
onPurchased({ creditsSpent, remainingBalance })Purchase succeeded
onUserLogin(user)User authenticated
onUserLogout()Session ended
onError({ message, error? })Any SDK error
Events vs callbacks

Callbacks in the config object and events via cc.on(...) cover the same moments. Use whichever fits your code style — they work identically. The full event list is in the Events reference.


Data attribute equivalents (CDN auto-init)

When using the CDN <script> tag, core options can be set as data-* attributes:

JS optiondata-* attribute
apiKeydata-api-key
contentSelectordata-content-selector
teaserParagraphsdata-teaser-paragraphs
enableCommentsdata-enable-comments
debugdata-debug
<script
src="https://cdn.contentcredits.com/sdk/v2/content-credits.umd.min.js"
data-api-key="pub_YOUR_KEY"
data-content-selector="#premium-content"
data-teaser-paragraphs="3"
data-enable-comments="true"
></script>
note

theme, articleUrl, extensionId, paywallTemplate, headless, and all callback options are JavaScript-only — they have no data-* equivalent.


Full option reference

For detailed descriptions of every option including types, defaults, and edge cases, see the Configuration Reference.