Skip to content

JavaScript SDK Banner

Programmatically show and control the PPP discount banner with the JavaScript SDK.

The JavaScript SDK can render a PPP discount banner similar to the standalone banner script, but with full programmatic control.

import { GoPayLocal } from '@gopaylocal/js';
const gpl = new GoPayLocal({ apiKey: 'gpl_pk_live_abc123' });
await gpl.init();
const banner = gpl.showBanner({
position: 'bottom-right',
});

The showBanner() method returns a handle with a remove() method:

// Remove the banner programmatically
banner.remove();

If no discount applies (visitor is from a Tier 1 country, VPN detected, etc.), showBanner() returns a no-op handle:

const banner = gpl.showBanner();
banner.remove(); // Safe to call, does nothing
OptionTypeDefaultDescription
position'top' | 'bottom' | 'bottom-left' | 'bottom-right''bottom'Banner position
backgroundColorstring'#1a1a2e'Background color
textColorstring'#ffffff'Text color
ctaColorstring'#e94560'CTA button color
ctaTextColorstring'#ffffff'CTA button text color
ctaTextstring'Copy Code'CTA button label
messageTemplatestringSee belowMessage with {{placeholders}}
showFlagbooleantrueShow country flag emoji
showCloseBtnbooleantrueShow close button
onClose() => voidCalled when banner is dismissed
Hey! It looks like you're visiting from {{countryName}}.
We support Purchasing Power Parity! Use code {{code}} for {{discount}}% off.
PlaceholderDescriptionExample
{{discount}}Discount percentage (number only)30
{{code}}Coupon codePPP-INDIA-30
{{country}}ISO country codeIN
{{countryName}}Full country nameIndia
{{currencySymbol}}Local currency symbol
{{currencyCode}}Local currency codeINR
{{flag}}Country flag emoji🇮🇳

You can use **bold text** in the template — it is rendered as <strong> elements.

gpl.showBanner({
position: 'top',
backgroundColor: '#1e3a5f',
textColor: '#ffffff',
ctaColor: '#4fc3f7',
ctaTextColor: '#1e3a5f',
});
gpl.showBanner({
messageTemplate:
'**{{countryName}} pricing!** Get {{discount}}% off with code **{{code}}**.',
ctaText: 'Copy Discount Code',
});
gpl.showBanner({
position: 'bottom-right',
onClose: () => {
console.log('Banner dismissed');
// Track in analytics
analytics.track('ppp_banner_dismissed');
},
});
const banner = gpl.showBanner({ position: 'bottom' });
// Remove after 30 seconds
setTimeout(() => {
banner.remove();
}, 30000);

Like the standalone banner script, the JavaScript SDK banner renders inside a Shadow DOM. This means:

  • Your site’s CSS cannot affect the banner
  • The banner’s CSS cannot leak into your site
  • The banner is completely isolated from your page

When the user clicks the CTA button:

  1. The coupon code is copied to the clipboard using navigator.clipboard.writeText()
  2. If that fails, a fallback using document.execCommand('copy') is used
  3. The button text changes to “Copied!” for 2 seconds
  4. The text reverts to the original CTA text

The banner slides in with a 300ms ease-out animation:

PositionAnimation
topSlides down from above the viewport
bottomSlides up from below the viewport
bottom-leftSlides in from the left
bottom-rightSlides in from the right