Skip to content

Installation

SaltyKeys.js is designed primarily for use in CodePen. The simplest approach is to add the script directly in your pen’s HTML or JS panel.

<script src="https://cdn.jsdelivr.net/gh/peterbenoit/SaltyKeys.js@main/SaltyKeys.js"></script>

Copy the contents of SaltyKeys.js and paste it into the JS panel of your pen. This keeps everything self-contained without an external request.

<script src="path/to/SaltyKeys.js"></script>

The SaltyKeys class is exposed as a global on window.

If you use SaltyKeys outside of CodePen, the default URL pattern won’t match your environment. You need to configure a custom urlPattern that captures your project identifier from the page URL.

SaltyKeys.configure({
urlPattern: /your-site\.com\/projects\/([^?#]+)/,
environment: 'custom',
});

Or override getPenId entirely:

SaltyKeys.getPenId = function () {
return window.location.pathname.split('/').pop();
};

See the configure() API reference for all available options.

Open your browser’s developer console and run:

console.log(typeof SaltyKeys); // → "function"
console.log(SaltyKeys.getPenId()); // → your pen ID, or null if URL doesn't match

If getPenId() returns null, check that your URL matches the configured urlPattern.