: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
import { useEffect } from 'react';
import Raven from '../lib/Raven';
requiresContentEmbedScope,
} from '../constants/leadinConfig';
import { App, AppIframe } from './constants';
import { messageMiddleware } from './messageMiddleware';
import { resizeWindow, useIframeNotRendered } from '../utils/iframe';
type PartialLeadinConfig = Pick<
| 'requiresContentEmbedScope'
type AppIntegrationConfig = Pick<LeadinConfig, 'adminUrl'>;
const getIntegrationConfig = (): AppIntegrationConfig => {
adminUrl: leadinQueryParams.adminUrl,
* A modified version of the original leadinConfig that is passed to some integrated apps.
* Try not to add new fields here.
* This config is already too large and broad in scope.
* It tightly couples the apps that use it with the WordPress plugin.
* Consider instead passing new required fields as new entry to PluginAppOptions or app-specific options.
const getLeadinConfig = (): AppLeadinConfig => {
const utm_query_params = Object.keys(leadinQueryParams)
.filter(x => /^utm/.test(x))
(p: { [key: string]: string }, c: string) => ({
[c]: leadinQueryParams[c],
admin: leadinQueryParams.admin,
company: leadinQueryParams.company,
email: leadinQueryParams.email,
firstName: leadinQueryParams.firstName,
irclickid: leadinQueryParams.irclickid,
justConnected: leadinQueryParams.justConnected,
lastName: leadinQueryParams.lastName,
mpid: leadinQueryParams.mpid,
nonce: leadinQueryParams.nonce,
trackConsent: leadinQueryParams.trackConsent,
websiteName: leadinQueryParams.websiteName,
requiresContentEmbedScope,
const getAppOptions = (app: App, createRoute = false) => {
options = new PluginAppOptions().setLeadinConfig(getLeadinConfig());
options = new PluginAppOptions()
.setLeadinConfig(getLeadinConfig())
.setPluginSettingsInit();
options = new FormsAppOptions().setIntegratedAppConfig(
options = options.setCreateFormAppInit();
options = new LiveChatAppOptions();
options = options.setCreateLiveChatAppInit();
options = new IntegratedAppOptions();
export default function useAppEmbedder(
container: HTMLElement | null
'HubSpot plugin - starting app embedder for:',
const iframeNotRendered = useIframeNotRendered(AppIframe[app]);
const { IntegratedAppEmbedder }: any = window;
if (IntegratedAppEmbedder) {
const options = getAppOptions(app, createRoute)
.setRefreshToken(refreshToken);
const embedder = new IntegratedAppEmbedder(
refreshToken ? '' : impactLink
embedder.subscribe(messageMiddleware(embedder));
embedder.attachTo(container, true);
embedder.postStartAppMessage(); // lets the app know all all data has been passed to it
(window as any).embedder = embedder;
console.error('HubSpot plugin Iframe not rendered', {
hasIntegratedAppEmbedder: !!(window as any).IntegratedAppEmbedder,
Raven.captureException(new Error('Leadin Iframe not rendered'), {
fingerprint: ['USE_APP_EMBEDDER', 'IFRAME_SETUP_ERROR'],
hasRefreshToken: !!refreshToken,
return iframeNotRendered;