@@ -318,34 +318,42 @@ var constructor = function () {
318318 launcherOptions || { }
319319 ) ;
320320
321- window . Rokt . createLauncher ( options )
322- . then ( function ( launcher ) {
323- // Assign the launcher to a global variable for later access
324- window . Rokt . currentLauncher = launcher ;
325- // Locally cache the launcher and filters
326- self . launcher = launcher ;
321+ if ( self . isPartnerInLocalLauncherTestGroup ( ) ) {
322+ var localLauncher = window . Rokt . createLocalLauncher ( options ) ;
323+ initRoktLauncher ( localLauncher ) ;
324+ }
325+ else {
326+ window . Rokt . createLauncher ( options )
327+ . then ( initRoktLauncher )
328+ . catch ( function ( err ) {
329+ console . error ( 'Error creating Rokt launcher:' , err ) ;
330+ } ) ;
331+ }
332+ }
327333
328- var roktFilters = window . mParticle . Rokt . filters ;
334+ function initRoktLauncher ( launcher ) {
335+ // Assign the launcher to a global variable for later access
336+ window . Rokt . currentLauncher = launcher ;
337+ // Locally cache the launcher and filters
338+ self . launcher = launcher ;
329339
330- if ( ! roktFilters ) {
331- console . warn ( 'Rokt Kit: No filters have been set.' ) ;
332- } else {
333- self . filters = roktFilters ;
334- if ( ! roktFilters . filteredUser ) {
335- console . warn (
336- 'Rokt Kit: No filtered user has been set.'
337- ) ;
338- }
339- }
340+ var roktFilters = window . mParticle . Rokt . filters ;
340341
341- // Kit must be initialized before attaching to the Rokt manager
342- self . isInitialized = true ;
343- // Attaches the kit to the Rokt manager
344- window . mParticle . Rokt . attachKit ( self ) ;
345- } )
346- . catch ( function ( err ) {
347- console . error ( 'Error creating Rokt launcher:' , err ) ;
348- } ) ;
342+ if ( ! roktFilters ) {
343+ console . warn ( 'Rokt Kit: No filters have been set.' ) ;
344+ } else {
345+ self . filters = roktFilters ;
346+ if ( ! roktFilters . filteredUser ) {
347+ console . warn (
348+ 'Rokt Kit: No filtered user has been set.'
349+ ) ;
350+ }
351+ }
352+
353+ // Kit must be initialized before attaching to the Rokt manager
354+ self . isInitialized = true ;
355+ // Attaches the kit to the Rokt manager
356+ window . mParticle . Rokt . attachKit ( self ) ;
349357 }
350358
351359 // mParticle Kit Callback Methods
@@ -402,6 +410,7 @@ var constructor = function () {
402410 this . setUserAttribute = setUserAttribute ;
403411 this . onUserIdentified = onUserIdentified ;
404412 this . removeUserAttribute = removeUserAttribute ;
413+ this . isPartnerInLocalLauncherTestGroup = isPartnerInLocalLauncherTestGroup ;
405414
406415 /**
407416 * Checks if the Rokt kit is ready to use.
@@ -413,6 +422,31 @@ var constructor = function () {
413422 function isKitReady ( ) {
414423 return ! ! ( self . isInitialized && self . launcher ) ;
415424 }
425+
426+ function isPartnerInLocalLauncherTestGroup ( ) {
427+ var testGroup = [ 382761173318339093846102813504170n ] ;
428+ var url = new URL ( window . location . href ) ;
429+ var { hostname } = url ;
430+ var hash = hashString ( hostname ) ;
431+
432+ return testGroup . includes ( hash ) ;
433+ }
434+
435+ /**
436+ * Generates a 64-bit integer hash from a string using the djb2 algorithm.
437+ * @param {string } str The string to hash.
438+ * @returns {bigint } A 64-bit BigInt representing the hash of the string.
439+ */
440+ function hashString ( str ) {
441+ var hash = 5381n ;
442+
443+ for ( let i = 0 ; i < str . length ; i ++ ) {
444+ var charCode = BigInt ( str . charCodeAt ( i ) ) ;
445+ hash = ( hash << 5n ) + hash + charCode ;
446+ }
447+
448+ return hash ;
449+ }
416450} ;
417451
418452function generateIntegrationName ( customIntegrationName ) {
0 commit comments