Package Exports
- ondc-campaign-sdk
- ondc-campaign-sdk/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ondc-campaign-sdk) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
๐๏ธ ONDC Campaign SDK
A lightweight & beautiful SDK to fetch and display live ONDC campaign products. Whether you're building a storefront, promotion landing page, or partner dashboard โ plug & play this SDK to show campaigns with style ๐
๐บ Watch How It Works
โจ Features
- ๐ข Campaign Info โ name, description, banner, and URLs
- ๐ Product Details โ seller, pricing, image, category, discount
- ๐จ Styled UI Renderer โ embed product cards with optional themes
- ๐ฑ Mobile Responsive โ optimized HTML ready for any screen
- โ๏ธ Zero Config โ just install & run. That's it.
๐ฆ Installation
npm install ondc-campaign-sdk
โก Quick Start
1. Fetch Campaign Products (Raw JSON)
import { fetchLiveCampaignProducts } from "ondc-campaign-sdk";
const data = await fetchLiveCampaignProducts();
console.log(data);
2. Render Dynamic Campaign Template
<div id="campaign-section"></div>
import { renderDynamicTemplate } from "ondc-campaign-sdk";
async function loadCampaignTemplate() {
const container = document.getElementById("campaign-section");
if (container) {
// Render campaign with order 1 (first campaign) and show 12 products
const html = await renderDynamicTemplate(1, 12);
container.innerHTML = html;
} else {
console.warn("Container #campaign-section not found.");
}
}
// Call the function
loadCampaignTemplate();
Parameters:
campignOrder
(number, default: 1) - Which campaign to fetch (1 = first, 2 = second, etc.)productCount
(number, default: 12) - Number of products to display
Template Selection:
The template is automatically selected based on the campaign's template_id
:
"light"
- Modern elegant template with clean white design"dark"
- Luxury premium template with dark theme- Fallback:
"light"
template if no template_id is specified
3. Generate Styled HTML (Alternative Method)
<div id="campaign-section"></div>
// @ts-ignore
import { fetchLiveCampaignProductsWithHtml } from "ondc-campaign-sdk";
async function loadLiveCampaignProducts() {
const container = document.getElementById("campaign-section");
if (container) {
const html = await fetchLiveCampaignProductsWithHtml(5); // show 5 products
container.innerHTML = html;
} else {
console.warn("Container #campaign-section not found.");
}
}
// Call the function
loadLiveCampaignProducts();
With custom styles:
const styles = {
primary: "#0d9488",
accent: "#ef4444",
bgLight: "#f0fdfa",
borderRadius: "16px",
};
const html = await fetchLiveCampaignProductsWithHtml(6, styles);
4. Render Campaign Carousel with Dynamic Styling
<div id="campaigns-carousel"></div>
import { renderCampaignsByCount } from "ondc-campaign-sdk";
async function loadCampaignsCarousel() {
const container = document.getElementById("campaigns-carousel");
if (container) {
// Render carousel with 5 campaigns
const html = await renderCampaignsByCount('5');
container.innerHTML = html;
} else {
console.warn("Container #campaigns-carousel not found.");
}
}
// Call the function
loadCampaignsCarousel();
Parameters:
count
(string, default: '') - Number of campaigns to fetch and display in carousel
Features:
- ๐ Bootstrap Carousel - Responsive carousel with navigation arrows and indicators
- ๐จ Dynamic Styling - Each campaign can have custom styling via
campaign_style
object - ๐ฑ Mobile Responsive - Optimized for all screen sizes
- ๐ฑ๏ธ Click Tracking - Automatic tracking of campaign clicks via transaction API
- ๐ Auto Rotation - Slides automatically every 5 seconds
Template Types:
classic
- Centered content with gradient backgroundsplit
- Left-aligned content with image backgroundoverlay
- Centered content with dark overlay cardmodern
- White floating card over image background
Dynamic Styling Options:
Each campaign can include a campaign_style
object with the following options:
interface CampaignStyle {
titleFontSize?: 'small' | 'medium' | 'large' | 'xl'; // Title font size
titleColor?: string; // Title color (hex/css color)
titleFontWeight?: 'normal' | 'bold' | 'bolder'; // Title font weight
descriptionFontSize?: 'small' | 'medium' | 'large'; // Description font size
descriptionColor?: string; // Description color
bannerTemplate?: 'classic' | 'split' | 'overlay' | 'modern'; // Template type
overlayOpacity?: number; // Overlay opacity (0.0 to 1.0)
showButton?: boolean; // Show/hide CTA button
buttonText?: string; // Custom button text
buttonBgColor?: string; // Button background color
buttonTextColor?: string; // Button text color
buttonBorderRadius?: number; // Button border radius (pixels)
buttonFontSize?: 'small' | 'medium' | 'large'; // Button font size
buttonFontWeight?: 'normal' | 'semibold' | 'bold'; // Button font weight
}
Example Campaign Data with Styling:
{
"_id": "campaign123",
"campaignName": "Summer Sale",
"description": "Get amazing summer discounts!",
"banner": "https://example.com/banner.jpg",
"campaign_style": {
"bannerTemplate": "overlay",
"titleFontSize": "large",
"titleColor": "#ffffff",
"titleFontWeight": "bold",
"descriptionFontSize": "medium",
"descriptionColor": "#e2e8f0",
"overlayOpacity": 0.6,
"showButton": true,
"buttonText": "Shop Now",
"buttonBgColor": "#10b981",
"buttonTextColor": "#ffffff",
"buttonBorderRadius": 12,
"buttonFontSize": "medium",
"buttonFontWeight": "semibold"
}
}
Template Examples:
// Classic template with custom styling
const classicCampaign = {
campaign_style: {
bannerTemplate: "classic",
titleFontSize: "xl",
titleColor: "#ffffff",
buttonBgColor: "#3b82f6",
buttonText: "Explore Collection"
}
};
// Split template for featured products
const splitCampaign = {
campaign_style: {
bannerTemplate: "split",
titleFontSize: "large",
overlayOpacity: 0.4,
buttonBgColor: "#ef4444",
buttonText: "Shop Category"
}
};
// Modern template with dark text
const modernCampaign = {
campaign_style: {
bannerTemplate: "modern",
titleColor: "#1f2937",
descriptionColor: "#4b5563",
buttonBgColor: "#8b5cf6",
showButton: true
}
};
๐งช API Response Format
{
"_id": "",
"campaignName": "",
"description": "",
"banner": "",
"products": [
{
"productId": "",
"additiveInfo": "",
"locations": "",
"brand": "",
"commonOrGenericNameOfCommodity": "",
"variantProducts": [],
"parentCategory": "",
"cancellable": "",
"vendorName": "",
"manufacturerName": "",
"aiProductName": "",
"attrTag": [
{
"code": "",
"list": [
{
"code": "",
"value": ""
}
]
}
],
"storefrontDays": [],
"vegTag": "",
"returnPickup": "",
"nutritionalInfo": "",
"deliveryTimeInShortText": "",
"productRatings": "",
"sellerId": "",
"isNonVeg": "",
"categoryName": [],
"aiCategoryName": "",
"unit": "",
"galleryImages": [
{
"url": "",
"type": ""
}
],
"hubId": "",
"tags": [],
"categoryId": [],
"availableOnCod": "",
"manufacturerAddress": "",
"brandName": "",
"groupAttributes": {
"G1": {
"Brand": "",
"Colour": ""
},
"G3": {
"Gross Weight Unit of Measurement": "",
"Length x Breadth x Height (Cubic Cm.)": ""
},
"G2": {
"Time to Ship": ""
},
"G4": {
"Manufacturer": "",
"COD available (Y/N)": "",
"Returnable (Y/N)": ""
},
"g1": {
"Cancellable (Y/N)": ""
}
},
"netQuantity": "",
"storeName": "",
"returnable": "",
"discountPercentage": "",
"winningVariant": "",
"timeToShipUnit": "",
"countryOfOrigin": "",
"socialCredsTags": [],
"discountedPrice": "",
"ondcCategoryId": "",
"discountEndDate": "",
"imgUrl": "",
"customerSupportDetails": "",
"variantValue": "",
"measureOfCommodityInPkg": "",
"manufacturingDate": "",
"monthYearOfManufacturePackingImport": "",
"timeToShip": "",
"customizedBlockId": "",
"providerId": "",
"estimatedDeliveryTime": "",
"unitAmount": "",
"tagsDetails": [],
"productName": "",
"ean": "",
"storeImage": "",
"regularPrice": "",
"returnWindow": "",
"_id": "",
"images": []
}
],
"isActive": "",
"createdAt": "",
"categories": [],
"__v": ""
}
๐จ Style Options (Optional)
{
primary: "#3d5af1",
primaryDark: "#2a3eb1",
accent: "#ff6b6b",
text: "#333333",
textLight: "#777777",
bgLight: "#f8f9fa",
white: "#ffffff",
shadow: "0 10px 30px rgba(0,0,0,0.08)",
borderRadius: "12px"
}
๐ License
MIT License ยฉ 2025 Samhita CGF
๐ค Contributing
We'd love your help to make this better!
- ๐ Report bugs
- ๐ก Suggest features
- ๐ฅ Submit pull requests
- ๐ Star the repo if you find it useful!
๐ฌ Support
Have a question or need help?
Feel free to reach out: mja@samhita.org
๐งฉ Coming Soon
- Filters by category or seller
- Sorting options (price, discount)
- Lazy loading for product lists
- CDN-ready minified build
Enjoy building cool stuff with ONDC ๐