Skip to content

Commit

Permalink
Avoid js TypeError when no BYG pages are configured
Browse files Browse the repository at this point in the history
The getMatchingAudiences function expects urls to be passed as an array,
but if there are no URLs configured for the site, that value is null.
This sets a sensible default to avoid console warnings bootstrapping the
BYG frontend.
  • Loading branch information
goldenapples committed Feb 27, 2024
1 parent 10fdfa0 commit 34d06d3
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/frontend.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ import { injectPage } from './services/history';
const defaultTrigger = ( BYG ) => {
const { callback, urls } = BYG;

BYG.url = getMatchingAudience( urls );
if ( callback && urls ) {
BYG.url = getMatchingAudience( urls );

callback( BYG );
callback( BYG );
}
};

/**
Expand All @@ -50,6 +52,7 @@ window.addEventListener( 'load', () => {
const BYG = Object.assign( {
referrers: [],
utmSources: [],
urls: [],
}, window.BYG || {} );

if ( typeof BYG.trigger === 'function' ) {
Expand Down

0 comments on commit 34d06d3

Please sign in to comment.