@@ -58,6 +58,14 @@ var constructor = function () {
5858 return baseUrl + '?extensions=' + extensions . join ( ',' ) ;
5959 }
6060
61+ /**
62+ * Checks if Rokt launcher is available and ready to attach
63+ * @returns {boolean } True if launcher can be attached
64+ */
65+ function isLauncherReadyToAttach ( ) {
66+ return window . Rokt && typeof window . Rokt . createLauncher === 'function' ;
67+ }
68+
6169 /**
6270 * Passes attributes to the Rokt Web SDK for client-side hashing
6371 * @see https://docs.rokt.com/developers/integration-guides/web/library/integration-launcher#hash-attributes
@@ -120,7 +128,9 @@ var constructor = function () {
120128 return ;
121129 }
122130
123- if ( ! window . Rokt || ! ( window . Rokt && window . Rokt . currentLauncher ) ) {
131+ if ( isLauncherReadyToAttach ( ) ) {
132+ attachLauncher ( accountId , launcherOptions ) ;
133+ } else {
124134 var target = document . head || document . body ;
125135 var script = document . createElement ( 'script' ) ;
126136 script . type = 'text/javascript' ;
@@ -131,12 +141,7 @@ var constructor = function () {
131141 script . id = 'rokt-launcher' ;
132142
133143 script . onload = function ( ) {
134- // Once the script loads, ensure the Rokt object is available
135- if (
136- window . Rokt &&
137- typeof window . Rokt . createLauncher === 'function' &&
138- window . Rokt . currentLauncher === undefined
139- ) {
144+ if ( isLauncherReadyToAttach ( ) ) {
140145 attachLauncher ( accountId , launcherOptions ) ;
141146 } else {
142147 console . error (
@@ -151,8 +156,6 @@ var constructor = function () {
151156
152157 target . appendChild ( script ) ;
153158 captureTiming ( PerformanceMarks . RoktScriptAppended ) ;
154- } else {
155- console . warn ( 'Unable to find Rokt on the page' ) ;
156159 }
157160 }
158161 /**
0 commit comments