Basic embed code structure
All Perch widgets use the same simple two-line integration. The widget ID will either be provided by your Perch representative (for custom configurations) or you can use one of the predefined static widget IDs for Lead Management:- Custom widgets: Your Perch representative provides a specific widget ID (e.g.,
ABC123
) - Static Lead Management widgets: Use predefined IDs following
static-{portal}-{parent}
format (see Widget Embedding for all available IDs)
Custom loading indicator
To improve the client user experience, we’ve added a feature to provide a custom loading indicator. You can use the inner<div>
with the class .perch-widget-loading-indicator
to insert a plain text loader (e.g. ‘Loading…’) that will be visible while the tool is being downloaded and rendered.
You can replace the contents of this <div>
with a custom message or a loading indicator of your choice to better match your branding:
Be sure that you retain the
.perch-widget-loading-indicator
class as this is what our script looks for when removing the loading indicator upon successful initialization of your widget.CMS-specific instructions
Important: In most cases, the CMS editor will not execute JavaScript and therefore the tool will not render in the editor. Instead you will see the “Loading…” text. To view the rendered tool, select your CMS’s “preview” option to see the live version.
WordPress + Elementor
- Navigate to the page where you want to embed the tool within your editor
- Add a new HTML element using Elementor
- Paste the provided
<div>
and<script>
tags into the HTML element - Save and publish your changes
Webflow
- Go to the page you wish to embed the tool on
- Add an Embed element to your page
- Paste the provided
<div>
and<script>
tags into the Embed element - Publish your site to see the tool in action
Squarespace
- Go to the page where you want to embed the tool
- Click on the + icon to add a new block and select Code
- Paste the provided
<div>
and<script>
tags into the Code block - Apply and save your changes
KVCore
KVCore is different from other website CMS in that you need to enter the<div>
and <script>
tags in different locations:
-
Add the script tag:
- Hover over Web & IDX in your sidebar navigation to reveal the menu
- Select Website Settings to open your website’s setting panel
- Scroll down to the custom header section
- Put your
<script>
tag in this box and hit save
-
Add the div portion:
- Go into your custom page editor
- Click the embed option
<>
- Paste the
<div>
portion of your tool into the box - Hit save and apply your changes to the site
Single Page Application integration
Perch Widgets can be easily integrated into single-page applications (SPAs) like Angular, Vue.js, or React. However, SPAs manage the DOM differently compared to traditional multi-page websites.Why manual initialization is needed
In a traditional setup, the widget script relies on the DOM ready event to initialize. But in SPAs, the DOM is often dynamically updated, and elements containing the widget may not be available at the traditional DOM ready event.Steps to initialize a widget in an SPA
- Insert the widget into your HTML as you normally would
- Listen for the appropriate lifecycle hook in your framework that guarantees the element containing the widget is present in the DOM
- Emit the Perch widget initialization event once the widget’s DOM element is available
Basic initialization code
Angular example
Vue.js example
React example
Best practices for SPAs
- Ensure that each widget is initialized only once per page, particularly in SPAs where pages may not fully reload
- Dispatch the event at the earliest point where you can guarantee the DOM element for the widget is present
- Clean up properly when components are unmounted to prevent memory leaks
Custom implementations
For custom implementations or unique technical requirements:- Include the script on your page (ideally in the
<head>
section) - Place the widget div where you want the tool to appear
- Trigger initialization manually if needed (for dynamic content)
Manual initialization
If you need to initialize widgets dynamically (e.g., after AJAX content loads):Troubleshooting
Widget not appearing
- Ensure the script tag is included on the page
- Check that the widget ID matches what was provided by Perch
- Verify JavaScript is enabled and not being blocked
Widget shows “Loading…” indefinitely
- Check browser console for JavaScript errors
- Ensure the page is being viewed live (not in editor mode)
- Verify the script URL is accessible
Multiple widgets on one page
- Each widget should have a unique widget-id
- The script only needs to be included once per page
- All widgets will initialize automatically