Add the main script into your page
1<!-- Load SDK -->
2<script src="https://cdn.jsdelivr.net/gh/NextCommerceCo/campaign-cart@v0.3.5/dist/loader.js" type="module"></script>
3
4<!-- Campaign API Key -->
5<meta name="next-api-key" content="kLGpgEfCX3iUZG16hpI5zrCH9qxcOdahDY1im6ud">
6
7<!-- Next URL After order complete (normally on checkout pages) -->
8<meta name="next-next-url" content="/upsell">
9
10<meta name="next-debug" content="true">
11<meta name="next-page-type" content="product"> <!-- Can be product, checkout, upsell, receipt -->
12
13<!-- Prevent Back navigation (normally on first upsell page) -->
14<meta name="next-prevent-back-navigation" content="true">
Action buttons & selectors are the core of the cart functionality. They work straight with attributes.
1<div data-next-cart-selector data-next-selection-mode="swap">
2 <div data-next-selector-card data-next-package-id="2">...</div>
3 <div data-next-selector-card data-next-package-id="3" data-next-selected="true">...</div>
4</div>
1<!-- Display current selection values -->
2<span data-next-display="selection.drone-packages.total">$35.98</span>
3<span data-next-display="selection.drone-packages.name">2x Drone</span>
4<span data-next-display="selection.drone-packages.unitPrice">$17.99</span>
5<span data-next-display="selection.drone-packages.savings">$22.00</span>
1<!-- Show/hide based on selection properties -->
2<div data-next-show="selection.drone-packages.hasSavings">
3 You save <span data-next-display="selection.drone-packages.savingsPercentage">55%</span>!
4</div>
5
6<!-- Comparison conditions -->
7<div data-next-show="selection.drone-packages.savings > 20">
8 Big savings alert!
9</div>
1<!-- Mathematical expressions -->
2<span data-next-display="selection.drone-packages.total*0.1">$3.60</span> <!-- 10% tax -->
3<span data-next-display="selection.drone-packages.total/4">$9.00</span> <!-- Split 4 ways -->
4<span data-next-display="selection.drone-packages.monthlyPrice">$3.00</span> <!-- Monthly -->
1<!-- Reference different selectors by ID -->
2<span data-next-display="selection.product-selector.name">Premium Drone</span>
3<span data-next-display="selection.color-selector.name">Midnight Black</span>
4<span data-next-display="selection.size-selector.name">Large</span>
1<div data-next-cart-selector
2 data-next-selector-id="button-selector"
3 data-next-selection-mode="select">
4 <div data-next-selector-card data-next-package-id="3">...</div>
5</div>
6
7<button data-next-action="add-to-cart"
8 data-next-selector-id="button-selector">
9 Add to Cart
10</button>
1<button data-next-action="add-to-cart"
2 data-next-package-id="2"
3 data-next-quantity="1">
4 Add to Cart
5</button>
6
7<button data-next-action="add-to-cart"
8 data-next-package-id="3"
9 data-next-quantity="3"
10 data-next-url="/checkout">
11 Add & Checkout
12</button>
1<button
2data-next-toggle
3data-next-is-upsell="true"
4data-next-package-id="9">
5Toggle Item
6</button>
1<button
2data-next-toggle
3data-next-package-id="8"
4data-next-quantity="3">
5Add Extra Propeller Set
6</button>
1<button
2data-next-toggle
3data-next-package-id="11"
4data-add-text="Add Extra Drone"
5data-remove-text="✓ Extra Drone Added">
6Add Extra Drone
7</button>
1<div class="product-container"
2data-next-package-id="9"
3data-next-quantity="2">
4<!-- Container gets state classes -->
5<button data-next-toggle>Toggle Bundle</button>
6</div>
1<!-- Warranty syncs with drone quantity -->
2<button data-next-toggle data-next-package-id="10" data-next-package-sync="2,3,4">
3Add Protection Plan
4</button>
5
1<script>
2 const packageId = 3;
3
4 function updateDisplay() {
5 const cartData = window.next.getCartData();
6 const item = cartData.cartLines?.find(line => line.packageId === packageId);
7 const quantity = item ? item.quantity : 0;
8 document.querySelector('[quantity="display"] div').textContent = quantity;
9
10 // Disable decrease button if quantity is 1 or less
11 const decreaseBtn = document.querySelector('[quantity="decrease"]');
12 if (quantity <= 1) {
13 decreaseBtn.disabled = true;
14 decreaseBtn.style.opacity = '0.5';
15 decreaseBtn.style.cursor = 'not-allowed';
16 } else {
17 decreaseBtn.disabled = false;
18 decreaseBtn.style.opacity = '1';
19 decreaseBtn.style.cursor = 'pointer';
20 }
21 }
22
23 document.querySelector('[quantity="decrease"]').addEventListener('click', function() {
24 const cartData = window.next.getCartData();
25 const item = cartData.cartLines?.find(line => line.packageId === packageId);
26 if (item && item.quantity > 1) {
27 window.next.updateQuantity({ packageId: packageId, quantity: item.quantity - 1 });
28 setTimeout(updateDisplay, 100);
29 }
30 });
31
32 document.querySelector('[quantity="increase"]').addEventListener('click', function() {
33 const cartData = window.next.getCartData();
34 const item = cartData.cartLines?.find(line => line.packageId === packageId);
35 const currentQuantity = item ? item.quantity : 0;
36 window.next.updateQuantity({ packageId: packageId, quantity: currentQuantity + 1 });
37 setTimeout(updateDisplay, 100);
38 });
39
40 updateDisplay();
41
42 </script>
Action buttons & selectors are the core of the cart functionality. They work straight with attributes.
1<!-- Load SDK -->
2<script src="https://campaign-cart-v2.pages.dev/loader.js"></script>
3
4<!-- Campaign API Key -->
5<meta name="next-api-key" content="kLGpgEfCX3iUZG16hpI5zrCH9qxcOdahDY1im6ud">
6
7<!-- Next URL After order complete (normally on checkout pages) -->
8<meta name="next-upsell-accept-url" content="/demo/receipt">
9<meta name="next-upsell-decline-url" content="/demo/receipt">
10
11<meta name="next-debug" content="true">
12<meta name="next-page-type" content="product"> <!-- Can be product, checkout, upsell, receipt -->
1<!-- Direct mode: package ID on container -->
2<div data-next-upsell="offer" data-next-package-id="7">
3 <h3>Add Extra Battery?</h3>
4 <button data-next-upsell-action="add">Yes</button>
5 <button data-next-upsell-action="skip">No</button>
6</div>
1<!-- Selector mode: uses selector ID -->
2<div data-next-upsell-selector data-next-selector-id="protection">
3 <div data-next-upsell-option data-next-package-id="7">
4 Basic - $14.99
5 </div>
6 <div data-next-upsell-option data-next-package-id="9" data-next-selected="true">
7 Premium - $24.99
8 </div>
9 <button data-next-upsell-action="add">
10 Add Selected
11 </button>
12</div>
1<!-- Wrap in upsell container -->
2<div data-next-upsell-selector data-next-selector-id="training">
3 <select data-next-upsell-select="training">
4 <option value="">Choose...</option>
5 <option value="2">Beginner - $29.99</option>
6 <option value="3" selected>Advanced - $49.99</option>
7 </select>
8
9 <button data-next-upsell-action="add">
10 Add Course
11 </button>
12</div>
1<!-- Quantity controls -->
2<div data-next-upsell="offer" data-next-package-id="7">
3 <button data-next-upsell-quantity="decrease">-</button>
4 <span data-next-upsell-quantity="display">1</span>
5 <button data-next-upsell-quantity="increase">+</button>
6
7 <button data-next-upsell-action="add">Add to Order</button>
8</div>
1<!-- Quantity toggle cards -->
2<div data-next-upsell="offer" data-next-package-id="7">
3 <div data-next-upsell-quantity-toggle="1">1 Pack</div>
4 <div data-next-upsell-quantity-toggle="2">2 Pack</div>
5 <div data-next-upsell-quantity-toggle="4">4 Pack</div>
6
7 <button data-next-upsell-action="add">
8 Add <span data-next-upsell-quantity="display">1</span> to Order
9 </button>
10</div>
Attributes are utilities that can be used to render content dynamically
Main utilities
1 <script>
2 // Wait for SDK to be fully initialized
3 window.addEventListener('next:initialized', function() {
4 console.log('SDK initialized, starting FOMO popups...');
5 // Simple usage - starts immediately with defaults
6 next.fomo();
7 // Optional: Listen to events for analytics
8 next.on('fomo:shown', (data) => {
9 console.log('FOMO shown:', data.customer, 'purchased', data.product);
10 });
11 });
12 // Control functions
13 function startFomo() {
14 next.fomo({
15 initialDelay: 2000, // Start after 2 seconds
16 displayDuration: 5000, // Show for 5 seconds
17 delayBetween: 10000 // 10 seconds between popups
18 });
19 }
20
21 function stopFomo() {
22 next.stopFomo();
23 }
24 // Custom configuration example
25 function customFomo() {
26 next.fomo({
27 items: [{
28 text: "Premium Bundle - Save 30%",
29 image: "https://example.com/premium-bundle.jpg"
30 }, {
31 text: "Starter Pack",
32 image: "https://example.com/starter-pack.jpg"
33 }],
34 customers: {
35 US: ["Sarah from Dallas", "Mike from Boston", "Lisa from Miami"],
36 CA: ["Jean from Montreal", "Pierre from Quebec", "Marie from Toronto"]
37 },
38 maxMobileShows: 3, // Show max 3 times on mobile
39 displayDuration: 4000,
40 delayBetween: 15000,
41 initialDelay: 0 // Start immediately
42 });
43 }
44 </script>
1 <script>
2 // Wait for SDK to be fully initialized
3 window.addEventListener('next:initialized', function() {
4 console.log('SDK initialized, setting up exit intent...');
5
6 // Super simple exit intent setup
7 next.exitIntent({
8 image: 'https://cdn.prod.website-files.com/68106277c04984fe676e423a/6823ba8d65474fce67152554_exit-popup1.webp',
9 action: async () => {
10 const result = await next.applyCoupon('SAVE10');
11 if (result.success) {
12 alert('Coupon applied successfully: ' + result.message);
13 } else {
14 alert('Coupon failed: ' + result.message);
15 }
16 }
17 });
18
19 // Optional: Listen to events for analytics
20 next.on('exit-intent:shown', (data) => {
21 console.log('Exit intent popup shown:', data.imageUrl);
22 });
23
24 next.on('exit-intent:clicked', (data) => {
25 console.log('Exit intent popup clicked:', data.imageUrl);
26 });
27
28 next.on('exit-intent:dismissed', (data) => {
29 console.log('Exit intent popup dismissed:', data.imageUrl);
30 });
31 });
32
33 // Even simpler examples:
34
35 // Just show a popup (no action)
36 function justShowPopup() {
37 next.exitIntent({
38 image: 'https://example.com/just-popup.webp'
39 });
40 }
41
42 // Redirect instead of coupon
43 function redirectExample() {
44 next.exitIntent({
45 image: 'https://example.com/special-offer.webp',
46 action: () => {
47 window.location.href = '/special-offer';
48 }
49 });
50 }
51
52 // Conditional popup based on cart
53 function conditionalExample() {
54 const cartCount = next.getCartCount();
55
56 if (cartCount === 0) {
57 next.exitIntent({
58 image: 'https://example.com/empty-cart.webp',
59 action: () => window.location.href = '/products'
60 });
61 } else {
62 next.exitIntent({
63 image: 'https://example.com/discount.webp',
64 action: () => next.applyCoupon('SAVE10')
65 });
66 }
67 }
68 </script>
