Configuration


  1. Go to Settings → Plugins → Dub Links in the Craft control panel.
  2. On the General tab, enter your Dub API key. You can use an environment variable (e.g. $DUB_API_KEY).
  3. After saving your API key, the Domain field will suggest your available domains. Pick one, or use an environment variable (e.g. $DUB_DOMAIN).
  4. In the Sections field, choose which sections to enable short links for. Leave All selected to enable every section that has URLs.
  5. On the Sidebar tab, choose how the QR code appears in the entry sidebar (None, Icon, or Full), set its style (size, margin, foreground/background colour), and choose whether to Show click count.

Checking it works #

The General tab has a Test button, and there is a console equivalent:

Plain Text
php craft dub/test

Both create a short link, read it back, fetch its QR code and delete it again, reporting each step. The write matters: an API key with no write scope, or a workspace at its link limit, passes every read and then fails the first time an editor saves an entry.

Domains per site #

The General tab also lists every site that has its own base URL, so each can have its own short link domain. Sites without one are left out, since their entries have no URLs to shorten, and the list only appears when more than one site qualifies. Leave a site blank and it uses the Domain above, and so does one set to an environment variable that isn't defined in the current environment. Each field suggests your Dub domains and accepts an environment variable, exactly like the main one.

This only affects links created or updated from then on. An existing link keeps the domain it was created on until its entry is next saved, so after changing a site's domain run:

Plain Text
php craft resave/entries

php craft dub/check reports the links still on the old domain as stale in the meantime, so you can see what is left to move.

Setting enabled sections via environment #

You can override the Sections selection with the DUB_SECTIONS environment variable, a comma-separated list of section handles:

Plain Text
DUB_SECTIONS=festivals,crew

When set, it takes precedence over the control panel selection (which is shown as read-only in the settings).