
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
astro-iubenda
Advanced tools
Astro integration for Iubenda Privacy Policy and Terms & Conditions
This Astro integration fetches and provides Iubenda Privacy Policy, Cookie Policy, and Terms & Conditions content for your Astro project.
Iubenda is a popular service that helps websites comply with legal requirements for privacy policies and terms of service. This integration simplifies the process of fetching and displaying Iubenda legal documents in your Astro project.
# Using npm
npm install astro-iubenda
# Using yarn
yarn add astro-iubenda
# Using pnpm
pnpm add astro-iubenda
To get your document IDs:
https://www.iubenda.com/privacy-policy/12345678
Where 12345678
is your document IDYou can also find this ID in the embedded code section as described in the Direct Text Embedding API documentation.
If you have policies in multiple languages or for different purposes, you can use multiple document IDs in the configuration.
Add the integration to your astro.config.mjs
file:
import { defineConfig } from "astro/config";
import iubenda from "astro-iubenda";
export default defineConfig({
// ...
integrations: [
iubenda({
documentIds: [<your-document-id>],
}),
],
});
Then import the documents in your Astro components:
---
import { getDocument } from 'virtual:astro-iubenda';
const privacyPolicy = getDocument(<your-document-id>, 'privacyPolicy');
const cookiePolicy = getDocument(<your-document-id>, 'cookiePolicy');
const termsAndConditions = getDocument(<your-document-id>, 'termsAndConditions');
---
<div set:html={privacyPolicy}></div>
To configure this integration, pass an options object to the iubenda()
function in your astro.config.mjs
file.
iubenda({
documentIds: [<your-document-id>],
saveInJson: true,
outputDir: "src/content/iubenda",
stripMarkup: true,
cookieFooter: {
iubendaOptions: {
// Your Iubenda Cookie Solution configuration
}
}
});
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
documentIds | Array<string | number> | Yes | - | Array of Iubenda document IDs to fetch. You can find your document ID in your Iubenda dashboard. |
saveInJson | boolean | No | false | Whether to write the fetched documents to disk as JSON files. |
outputDir | string | No | 'src/content/iubenda' | Directory where JSON files will be written if saveInJson is true. |
stripMarkup | boolean | No | true | Whether to strip HTML markup from the fetched documents. |
cookieFooter | false | CookieFooterOptions | No | false | Configuration for Iubenda Cookie Solution banner. See TypeScript types for full options. |
The integration supports Iubenda's Cookie Solution banner through the cookieFooter
option. When enabled, it automatically injects the necessary scripts into your pages.
iubenda({
documentIds: ["12345678"],
cookieFooter: {
// Required: The configuration object from your Iubenda dashboard
iubendaOptions: {
siteId: 12345678,
cookiePolicyId: 87654321,
lang: "en",
// Add any other Iubenda configuration options
},
// Optional: Google Tag Manager integration
googleTagManagerOptions: true, // or customize with an object
// Optional: Where to inject the banner scripts
injectionStage: "head-inline", // or "page"
// Optional: Banner version to use
bannerVersion: "current", // "current", "beta", or "stable"
},
});
Option | Type | Required | Default | Description |
---|---|---|---|---|
iubendaOptions | IubendaOptions | Yes | - | The _iub.csConfiguration object you copy from the Iubenda dashboard. |
googleTagManagerOptions | boolean | { eventName?: string; dataLayerName?: string } | No | false | Enable Google Tag Manager integration. Set to true to use defaults, or provide an object to customize. |
injectionStage | "head-inline" | "page" | No | "head-inline" | Where to inject the banner scripts. "head-inline" is recommended by Iubenda. |
bannerVersion | "current" | "beta" | "stable" | No | "current" | The version of the Iubenda banner to use. |
When googleTagManagerOptions
is enabled:
iubenda_consent_given
to the dataLayer
as explained by the official Iubenda guidecookieFooter: {
iubendaOptions: { /* ... */ },
googleTagManagerOptions: {
eventName: "cookie_consent_given",
dataLayerName: "customDataLayer"
}
}
The integration provides a virtual module that you can import in your components.
The integration exports comprehensive TypeScript types for better development experience:
// Import types for configuration
import type {
CookieFooterOptions,
IubendaOptions,
IubendaCallbacks,
HexColor,
BannerVersion,
TcfPurposesKeys,
ConsentEventName,
} from "astro-iubenda";
Available Types:
CookieFooterOptions
- Main configuration interface for cookie footerIubendaOptions
- Complete Iubenda configuration objectIubendaCallbacks
- All available callback functionsHexColor
- Type-safe hex color string (#${string}
)BannerVersion
- Banner version options ("current"
, "beta"
, "stable"
)TcfPurposesKeys
- TCF purpose IDs ("1"
through "10"
)ConsentEventName
- Consent event types for callbacksFull object with all fetched documents, keyed by document ID.
import { documents } from "virtual:astro-iubenda";
// Access all policies for a specific document ID
const allPolicies = documents["12345678"];
// Access a specific policy directly
const privacyPolicy = documents["12345678"].privacyPolicy;
Parameters:
id
- Document ID to retrievetype
- Type of document ('privacyPolicy', 'cookiePolicy', or 'termsAndConditions')Returns: The document content as a string, or null if not found.
import { getDocument } from "virtual:astro-iubenda";
const privacyPolicy = getDocument("12345678", "privacyPolicy");
---
import { getDocument } from 'virtual:astro-iubenda';
---
<html>
<head>
<title>Privacy Policy</title>
</head>
<body>
<h1>Our Privacy Policy</h1>
<div set:html={getDocument('12345678', 'privacyPolicy')}></div>
</body>
</html>
---
import { documents } from 'virtual:astro-iubenda';
// Access all documents and their types for a specific ID
const docId = '12345678';
const allDocsForId = documents[docId];
// Access specific documents directly
const privacyPolicy = documents[docId].privacyPolicy;
const cookiePolicy = documents[docId].cookiePolicy;
const terms = documents[docId].termsAndConditions;
---
<h2>Available Documents</h2>
<ul>
{privacyPolicy && <li><a href="/privacy">Privacy Policy</a></li>}
{cookiePolicy && <li><a href="/cookies">Cookie Policy</a></li>}
{terms && <li><a href="/terms">Terms and Conditions</a></li>}
</ul>
<!-- Using the full document object -->
<div class="policies">
{Object.entries(allDocsForId).map(([type, content]) => (
<div class="policy-preview">
<h3>{type}</h3>
<div class="preview" set:html={content.substring(0, 200) + '...'} />
</div>
))}
</div>
// astro.config.mjs
import { defineConfig } from "astro/config";
import iubenda from "astro-iubenda";
export default defineConfig({
integrations: [
iubenda({
documentIds: ["12345678", "87654321"],
saveInJson: true,
}),
],
});
---
import { documents } from 'virtual:astro-iubenda';
---
<select id="policy-selector">
<option value="12345678">English</option>
<option value="87654321">Spanish</option>
</select>
<div id="policy-content"></div>
<script>
const selector = document.getElementById('policy-selector');
const content = document.getElementById('policy-content');
const documents = {JSON.stringify(documents)};
selector.addEventListener('change', () => {
const id = selector.value;
content.innerHTML = documents[id].privacyPolicy;
});
// Set initial content
content.innerHTML = documents[selector.value].privacyPolicy;
</script>
import type { IubendaCallbacks, ConsentEventName } from "astro-iubenda";
const callbacks: IubendaCallbacks = {
onReady: (hasConsent: boolean) => {
console.log("Iubenda ready, has consent:", hasConsent);
},
onBannerShown: () => {
console.log("Banner shown");
},
onBannerClosed: () => {
console.log("Banner closed");
},
onConsentGiven: (consent: boolean) => {
console.log("Consent given:", consent);
// Enable analytics, tracking, etc.
},
onConsentFirstGiven: (event: ConsentEventName) => {
console.log("First consent given via:", event);
// Track conversion event
},
onConsentRejected: () => {
console.log("Consent rejected");
// Disable tracking
},
onPreferenceExpressed: (preferences: unknown) => {
console.log("User preferences:", preferences);
},
onPreferenceNotNeeded: () => {
console.log("No preference needed for this user");
},
onCcpaOptOut: () => {
console.log("User opted out (CCPA)");
},
onError: (message: string) => {
console.error("Iubenda error:", message);
},
};
// Use in your config
export default defineConfig({
integrations: [
iubenda({
documentIds: ["12345678"],
cookieFooter: {
iubendaOptions: {
siteId: 12345678,
cookiePolicyId: 87654321,
lang: "en",
callback: callbacks,
},
},
}),
],
});
import type { HexColor } from "astro-iubenda";
// Type-safe hex color definitions
const brandColors = {
primary: "#0073aa" as HexColor,
secondary: "#005177" as HexColor,
accent: "#00a0d2" as HexColor,
dark: "#1e1e1e" as HexColor,
light: "#f7f7f7" as HexColor,
} as const;
export default defineConfig({
integrations: [
iubenda({
documentIds: ["12345678"],
cookieFooter: {
iubendaOptions: {
siteId: 12345678,
cookiePolicyId: 87654321,
lang: "en",
banner: {
backgroundColor: brandColors.dark,
textColor: brandColors.light,
acceptButtonColor: brandColors.primary,
acceptButtonCaptionColor: brandColors.light,
customizeButtonColor: brandColors.secondary,
customizeButtonCaptionColor: brandColors.light,
rejectButtonColor: brandColors.accent,
rejectButtonCaptionColor: brandColors.light,
brandTextColor: brandColors.primary,
brandBackgroundColor: brandColors.light,
},
floatingPreferencesButtonColor: brandColors.primary,
floatingPreferencesButtonCaptionColor: brandColors.light,
},
},
}),
],
});
// Define configurations for different languages/regions
const configs = {
en: {
siteId: 12345678,
cookiePolicyId: 87654321,
lang: "en",
enableGdpr: true,
enableCcpa: true,
},
es: {
siteId: 12345678,
cookiePolicyId: 11111111,
lang: "es",
enableGdpr: true,
enableLgpd: true,
},
de: {
siteId: 12345678,
cookiePolicyId: 22222222,
lang: "de",
enableGdpr: true,
gdprAppliesGlobally: true,
},
} as const;
export default defineConfig({
integrations: [
iubenda({
documentIds: ["87654321", "11111111", "22222222"],
cookieFooter: {
// Use the English config as default
iubendaOptions: configs.en,
googleTagManagerOptions: true,
},
}),
],
});
GDPR Configuration:
cookieFooter: {
iubendaOptions: {
siteId: 12345678,
cookiePolicyId: 87654321,
lang: "en",
enableGdpr: true,
gdprAppliesGlobally: false,
perPurposeConsent: true,
purposes: "1,2,3,4,5",
}
}
Custom Banner Styling:
cookieFooter: {
iubendaOptions: {
siteId: 12345678,
cookiePolicyId: 87654321,
lang: "en",
banner: {
position: "float-bottom-right",
acceptButtonDisplay: true,
customizeButtonDisplay: true,
rejectButtonDisplay: true,
backgroundColor: "#000000",
textColor: "#ffffff",
acceptButtonColor: "#0073aa",
acceptButtonCaptionColor: "#ffffff",
customizeButtonColor: "#dadada",
customizeButtonCaptionColor: "#000000",
rejectButtonColor: "#0073aa",
rejectButtonCaptionColor: "#ffffff",
}
}
}
CCPA (California) Configuration:
cookieFooter: {
iubendaOptions: {
siteId: 12345678,
cookiePolicyId: 87654321,
lang: "en",
enableCcpa: true,
ccpaApplies: true,
ccpaNoticeDisplay: true,
ccpaAcknowledgeOnDisplay: true,
},
googleTagManagerOptions: {
eventName: "ccpa_consent_given",
dataLayerName: "dataLayer"
}
}
IAB TCF v2 Configuration:
cookieFooter: {
iubendaOptions: {
siteId: 12345678,
cookiePolicyId: 87654321,
lang: "en",
enableTcf: true,
googleAdditionalConsentMode: true,
tcfPurposes: {
"1": "consent_only",
"2": "consent_only",
"3": "li_only",
"4": "consent_not_needed"
},
askConsentIfCMPNotFound: true,
}
}
Multi-compliance Setup (GDPR + CCPA + LGPD):
cookieFooter: {
iubendaOptions: {
siteId: 12345678,
cookiePolicyId: 87654321,
lang: "en",
countryDetection: true,
// GDPR
enableGdpr: true,
gdprAppliesGlobally: false,
// CCPA
enableCcpa: true,
ccpaApplies: true,
// LGPD
enableLgpd: true,
lgpdAppliesGlobally: false,
// UI Configuration
banner: {
acceptButtonDisplay: true,
customizeButtonDisplay: true,
rejectButtonDisplay: true,
listPurposes: true,
showPurposesToggles: true,
}
},
googleTagManagerOptions: true,
bannerVersion: "current"
}
You're welcome to submit an issue or PR!
See GitHub releases for a history of changes to this integration.
MIT - see LICENSE for details.
0.4.1
FAQs
Astro integration for Iubenda Privacy Policy and Terms & Conditions
The npm package astro-iubenda receives a total of 41 weekly downloads. As such, astro-iubenda popularity was classified as not popular.
We found that astro-iubenda demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.