react-calendly

repository·master·Indexed 43 days ago

https://github.com/tcampb/react-calendly

A React wrapper for Calendly embed options (version 4.4.0) that allows developers to integrate scheduling workflows via InlineWidget, PopupWidget, PopupButton, and PopupModal. It includes the useCalendlyEventListener hook to track events like onEventScheduled and onDateAndTimeSelected, as well as support for prefilling user data, UTM tracking, and custom page settings.

Tokens
5K
Snippets
18
Records
19
Agent score
52%

What's inside react-calendly

  1. Configure InlineWidget with advanced props

    master

    You can customize the InlineWidget using several optional props:

    • styles: An object to define CSS styles, such as height.
    • pageSettings: Customizes the appearance (e.g., backgroundColor, primaryColor, textColor, hideEventTypeDetails, hideLandingPageDetails). Note: Custom colors require a Calendly Pro plan.
    • prefill: An object to pre-populate user information like email, firstName, lastName, name, guests (array of emails), customAnswers (object), or date (Date object).
    • utm: An object containing UTM parameters (utmCampaign, utmContent, utmMedium, utmSource, utmTerm) for tracking.
    // Example of combined advanced props
    <InlineWidget 
      url="https://calendly.com/your_scheduling_page"
      styles={{ height: '1000px' }}
      pageSettings={{
        backgroundColor: 'ffffff',
        primaryColor: '00a2ff',
      }}
      prefill={{
        email: 'test@test.com',
        firstName: 'Jon',
        lastName: 'Snow'
      }}
      utm={{
        utmSource: 'Facebook'
      }}
    />
  2. Create a custom button to trigger PopupModal

    master

    If you want to use your own UI component (like a custom styled button) to trigger the Calendly popup, use the PopupModal component. You can control its visibility using the open prop and handle closing via onModalClose.

    import { PopupModal } from "react-calendly";
    
    class CustomButtonExample extends React.Component {
      constructor(props) {
        super(props);
        this.state = { isOpen: false };
      }
    
      render() {
        return (
          <div>
            <button onClick={() => this.setState({ isOpen: true })}>
              Custom Button
            </button>
            <PopupModal
              url="https://calendly.com/acmesales"
              open={this.state.isOpen}
              onModalClose={() => this.setState({ isOpen: false })}
              rootElement={document.getElementById("root")}
            />
          </div>
        );
      }
    }
  3. Use the InlineWidget component

    master

    The InlineWidget component embeds the Calendly scheduling page directly into your application's layout. It requires a url prop pointing to your Calendly scheduling page.

    import React from "react";
    import { InlineWidget } from "react-calendly";
    
    const App = () => {
      return (
        <div className="App">
          <InlineWidget url="https://calendly.com/your_scheduling_page" />
        </div>
      );
    };
    
    export default App;
  4. Listen to Calendly events with useCalendlyEventListener

    master

    The useCalendlyEventListener hook allows you to react to events occurring within the Calendly widget (such as page views, date selection, or successful scheduling).

    Available event handlers include:

    • onProfilePageViewed
    • onDateAndTimeSelected
    • onEventTypeViewed
    • onEventScheduled: Receives an object containing e.data.payload with event and invitee URIs.
    • onPageHeightResize: Receives an object containing e.data.payload.height.
    import React from "react";
    import { useCalendlyEventListener, InlineWidget } from "react-calendly";
    
    const App = () => {
      useCalendlyEventListener({
        onProfilePageViewed: () => console.log("onProfilePageViewed"),
        onDateAndTimeSelected: () => console.log("onDateAndTimeSelected"),
        onEventTypeViewed: () => console.log("onEventTypeViewed"),
        onEventScheduled: (e) => console.log(e.data.payload),
        onPageHeightResize: (e) => console.log(e.data.payload.height),
      });
    
      return (
        <div className="App">
          <InlineWidget url="https://calendly.com/your_scheduling_page" />
        </div>
      );
    };
  5. Use the PopupWidget component

    master

    The PopupWidget component renders a floating widget that opens a Calendly modal.

    Note: Because react-calendly uses React Portals, you must provide the rootElement prop (typically document.getElementById('root')) to ensure the modal is correctly inserted into the DOM.

    import React from "react";
    import { PopupWidget } from "react-calendly";
    
    const App = () => {
      return (
        <div className="App">
          <PopupWidget
            url="https://calendly.com/your_scheduling_page"
            rootElement={document.getElementById("root")}
            text="Click here to schedule!"
            textColor="#ffffff"
            color="#00a2ff"
          />
        </div>
      );
    };
  6. Use the PopupButton component

    master

    The PopupButton component renders a standard button that, when clicked, triggers the Calendly popup modal. Like PopupWidget, it requires the rootElement prop for React Portal support.

    import React from "react";
    import { PopupButton } from "react-calendly";
    
    const App = () => {
      return (
        <div className="App">
          <PopupButton
            url="https://calendly.com/your_scheduling_page"
            rootElement={document.getElementById("root")}
            text="Click here to schedule!"
          />
        </div>
      );
    };
  7. Configure PageSettings for embedded Calendly

    master

    The PageSettings object allows you to customize the appearance and behavior of the embedded Calendly iframe. Note that some styling options require a Calendly Pro plan.

    KeyTypeDescription
    hideLandingPageDetailsbooleanHides profile picture, name, event duration, location, and description on the landing page.
    hideEventTypeDetailsbooleanHides profile picture, name, event duration, location, and description on the event type page.
    backgroundColorstringChanges the background color (e.g., 00a2ff). Requires Pro plan.
    textColorstringChanges the text color (e.g., ffffff). Requires Pro plan.
    primaryColorstringChanges the primary color (e.g., 4d5055). Requires Pro plan.
    hideGdprBannerbooleanHides the GDPR consent banner.
  8. Configure UTM and Salesforce tracking parameters

    master

    You can pass tracking parameters to the Calendly URL using the Utm type to support marketing attribution and CRM integration.

    Supported keys:

    • utmCampaign
    • utmSource
    • utmMedium
    • utmContent
    • utmTerm
    • salesforce_uuid: Used for Salesforce integration.
    const utm: Utm = {
      utmSource: 'newsletter',
      utmMedium: 'email',
      salesforce_uuid: '12345-abcde'
    };
  9. Listen to Calendly iframe events with useCalendlyEventListener

    master

    Use the useCalendlyEventListener hook to intercept and respond to events emitted by the Calendly iframe. This hook sets up a window message listener and provides typed event handlers for common scheduling lifecycle events.

    Supported Event Handlers

    HandlerEvent TypePayload Description
    onDateAndTimeSelectedDATE_AND_TIME_SELECTEDTriggered when a user selects a date and time.
    onEventScheduledEVENT_SCHEDULEDTriggered when an event is successfully scheduled. Includes uri for the event and the invitee.
    onEventTypeViewedEVENT_TYPE_VIEWEDTriggered when a specific event type page is viewed.
    onProfilePageViewedPROFILE_PAGE_VIEWEDTriggered when the profile page is viewed.
    onPageHeightResizePAGE_HEIGHTTriggered when the iframe height changes. Includes height as a string (e.g., "1200px").
    import useCalendlyEventListener from 'react-calendly/hooks/useCalendlyEventListener';
    
    function MyComponent() {
      useCalendlyEventListener({
        onEventScheduled: (e) => {
          console.log('Event scheduled!', e.data.payload.event.uri);
        },
        onPageHeightResize: (e) => {
          console.log('New height:', e.data.payload.height);
        }
      });
    
      return <div>Calendly integration active</div>;
    }
  10. Configure Prefill data for Calendly URLs

    master

    You can pre-populate Calendly scheduling forms with user information using the Prefill type. This is useful for reducing friction during the booking process.

    Supported fields include:

    • name: Full name
    • email: User's email address
    • firstName: First name
    • lastName: Last name
    • location: User's location
    • guests: An array of guest names (strings)
    • date: A JavaScript Date object
    • customAnswers: An object containing custom question responses using keys a1 through a10 (e.g., { a1: 'Response' }).
    const prefill: Prefill = {
      name: 'John Doe',
      email: 'john@example.com',
      firstName: 'John',
      lastName: 'Doe',
      customAnswers: {
        a1: 'Answer to question 1'
      }
    };
  11. Format Calendly URLs with formatCalendly()

    master

    The formatCalendlyUrl function constructs a fully qualified Calendly URL by appending query parameters for prefilling, page settings, UTM tracking, and embed types to a base URL.

    Parameters:

    • url (string): The base Calendly URL.
    • prefill (Optional<Prefill>): User data to pre-populate the form.
    • pageSettings (Optional<PageSettings>): Visual and behavioral settings for the embed.
    • utm (Optional<Utm>): Marketing and tracking parameters.
    • embedType (Optional<'Inline' | 'PopupWidget' | 'PopupButton'>): The type of embed being used.
    import { formatCalendlyUrl } from 'react-calendly';
    
    const url = formatCalendlyUrl({
      url: 'https://calendly.com/your-profile/event-name',
      prefill: {
        email: 'user@example.com',
        firstName: 'User'
      },
      pageSettings: {
        hideLandingPageDetails: true,
        primaryColor: '4d5055'
      },
      embedType: 'Inline'
    });
    
    // Result: https://calendly.com/your-profile/event-name?hide_landing_page_details=1&primary_color=4d5055&email=user%40example.com&first_name=User&embed_type=Inline&embed_domain=1