This guide will walk you through implementing a campus selector for the Pushpay embedded giving widget.
This is a powerful feature for organizations with multiple locations, allowing givers to direct their generosity to their home campus right from your website. We'll cover how campuses are structured in Pushpay and provide a step-by-step guide with template code you can use to create a seamless and personalised campus-specific giving experience.
Caution: The following instructions are intended for web developers and require a good understanding of HTML, CSS, and Javascript. Customizations beyond those listed here are possible but may not be supported by our team and could break when we update the widget.
Before implementing the campus selector on your website, we strongly recommend exploring the demo to understand the user experience:
- Open the Demo: Open
embedded-listing-selector-demo.htmlin your web browser - Test Campus Selection: Click on different campus options to see how the widget loads dynamically
- Observe the Transition: Notice how selected campuses highlight and non-selected options fade away
- Test the "Change Campus" Link: After selecting a campus, click "Change Campus" to return to the selection menu
- Test Cookie Persistence: After selecting a campus, refresh the page. The widget should automatically load your previously selected campus
- Note: To test cookie persistence locally, you must run the demo through a local web server (e.g., using
python -m http.serveror a tool like Live Server in VS Code). Opening the HTML file directly withfile://protocol will prevent cookies from working properly.
- Note: To test cookie persistence locally, you must run the demo through a local web server (e.g., using
- Inspect the Code: View the page source to see the HTML structure and how elements are organized
The demo includes three sample campuses with working Pushpay QA handles. This hands-on exploration will help you understand how the selector works before you begin customizing it for your organization.
Before you start, it's crucial to understand how your organization's campuses are set up in Pushpay, as this determines the correct implementation path. There are two primary methods:
- Single Listing with a Campus Field: In this setup, your organization has one primary giving listing. The widget itself will contain a dropdown field labeled "Campus" where givers can select their location. If this is your configuration, you do not need this guide! The standard widget will handle campus selection automatically.
- Separate Listing for Each Campus: In this configuration, each campus has its own unique Pushpay giving listing. This means each campus has a different handle used in the widget loader script. The solution in this guide is designed specifically for this scenario. It works by dynamically swapping the widget handle based on the user's selection and history.
To confirm your setup, check your Pushpay Giving admin portal or contact Pushpay support.
The Javascript code provided here creates a dynamic and user-friendly experience. Here’s a quick overview of what it does:
- Detects Selection: It listens for a click within your website's campus navigation menu.
- Loads the Correct Widget: When a user selects a campus, the script grabs the unique handle associated with that campus and loads the giving widget with that handle.
- Remembers the User: It saves the user’s campus choice in a browser cookie.
- Personalizes Future Visits: The next time the user visits your giving page, the script reads the cookie and automatically loads the widget for their previously selected campus, creating a personalized experience.
- Handles Widget Cleanup: When switching between campuses, the script properly destroys the previous widget instance before loading the new one, ensuring a clean transition.
- Provides Fallback: If the widget fails to load (network issues, script errors), it displays a fallback "Give Now" button that redirects to the campus's full giving page with a Custom Campus/Listing Selector
First, you need an HTML element on your website that allows users to select a campus. This is typically a list of tiles or a dropdown menu on the giving page.
Required HTML Structure:
- A wrapper
<div>with the classpushpay-widget - An
<h2>with classpushpay-campus-select-labelfor the heading - A
<ul>with classpushpay-listing-select-menucontaining campus options - Each campus as an
<li>element containing an<a>tag with adata-handleattribute - A hidden wrapper
<div>with idpushpay-wrappercontaining the widget container - A hidden "Change Campus" link with id
pushpay-change-campus-link - The script tag pointing to
embedded-listing-selector.js
Here is an example structure. You will need to replace the data-handle values with the correct handles for your organization's listings from your Pushpay admin portal.
<div class="pushpay-widget" data-env="prod">
<h2 class="pushpay-campus-select-label">Select your campus:</h2>
<ul class="pushpay-listing-select-menu">
<li><a href="#" data-handle="your-campus-1-handle">Campus Name 1</a></li>
<li><a href="#" data-handle="your-campus-2-handle">Campus Name 2</a></li>
<li><a href="#" data-handle="your-campus-3-handle">Campus Name 3</a></li>
</ul>
<div id="pushpay-wrapper" class="hidden">
<div id="pushpay-embedded-giving"></div>
</div>
<a id="pushpay-change-campus-link" style="display: none;">Change Campus</a>
<script src="embedded-listing-selector.js"></script>
</div>The data-env attribute on the main wrapper div controls which Pushpay environment the widget connects to:
For Production (Live Giving):
<div class="pushpay-widget" data-env="prod">or simply omit the attribute (production is the default):
<div class="pushpay-widget">For the demo page (or testing using the test listings from the demo page):
<div class="pushpay-widget" data-env="qa">Important Notes:
- You may use
data-env="qa"during development and testing with the Pushpay demo page listings - To test the page with your real listings, either change
data-env="qa"todata-env="prod"or remove the attribute entirely - QA handles point to
qa.testpushpay.comwhile production handles point topushpay.com
To find your listing handles, visit your existing Pushpay giving pages. The handle is the last part of the URL.
For example, in the URL https://pushpay.com/g/givecentralchurch, the handle is givecentralchurch
Handle Format: Handles are usually lowercase alphanumeric strings without spaces (e.g., givecentralchurch, downtowncampus, northlocation)
You can add custom styling to the <li> elements and other components to achieve rich and dynamic menus like the one in the demo page. You are welcome to incorporate the styles from widget-styles.css and demo-styles.css into your own stylesheet, or amend them to match your brand.
The script automatically applies the following CSS classes during interaction:
hidden- Applied to non-selected campus tiles when a selection is madeselected- Applied to the chosen campus tilevisible- Applied to the widget wrapper when the widget loads
You can use these classes in your CSS to create smooth transitions and visual feedback.
Make sure embedded-listing-selector.js is accessible from your HTML file. You can either:
- Place it in the same directory as your HTML file
- Place it in a scripts folder and update the path:
<script src="/js/embedded-listing-selector.js"></script> - Host it on a CDN if you prefer
The script will automatically initialize when the DOM is ready, so no additional JavaScript code is needed.
- Test in QA first: Set
data-env="qa"and use Pushpay QA handles - Test each campus: Click through each campus option to ensure the correct widget loads
- Test cookie persistence: Select a campus, close your browser, reopen, and verify it remembers your choice
- Test the "Change Campus" link: Ensure you can switch between campuses smoothly
- Test on multiple browsers: Verify functionality in Chrome, Firefox, Safari, and Edge
- Test on mobile devices: Ensure the experience works well on phones and tablets
Once testing is complete:
- Update
data-envto"prod"or remove the attribute - Replace all QA handles with production handles
- Deploy to your production website
- Test again in production to ensure everything works correctly
Widget not loading:
- Verify your handles are correct for your environment (QA vs. production)
- Check browser console for JavaScript errors
- Ensure the
embedded-listing-selector.jsfile path is correct - Verify the HTML structure matches the required format
Campus selection not working:
- Ensure each
<a>tag has adata-handleattribute - Verify the
<li>and<a>structure is correct - Check for JavaScript errors in the browser console
Cookie not persisting:
- Check if browser cookies are enabled
- Verify there are no cookie-blocking extensions active
- Ensure your website is served over HTTPS (some browsers restrict cookies on HTTP)
- If testing locally, make sure you're running a local web server (not opening files directly with
file://protocol). Use tools like:- Python:
python -m http.serverorpython3 -m http.server - Node.js:
npx http-serverornpx serve - VS Code: Live Server extension
- Python:
Widget shows wrong campus after refresh:
- Clear browser cookies and test again
- Verify the cookie name
PushpaySelectedCampusisn't being set elsewhere in your code
- No Dependencies: The script uses pure vanilla JavaScript with no external dependencies
- Browser Support: Compatible with all modern browsers (Chrome, Firefox, Safari, Edge)
- Cookie Expiration: Campus selection is remembered for 365 days
- Widget Cleanup: The script properly cleans up widget instances when switching campuses to prevent memory leaks
- Fallback Handling: If the widget fails to load within 3 seconds, a fallback "Give Now" button appears that redirects to the full giving page
That's it! With the HTML structure and this script in place, your website will now offer a dynamic, campus-specific giving experience that remembers your donors' preferences and provides a seamless giving journey.