/** * Copyright 2025 Wingify Software Pvt. Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import React from 'react'; interface VWOScriptProps { accountId: string; type?: 'ASYNC' | 'SYNC'; settingsTimeout?: number; hideElement?: string; hideElementStyle?: string; scriptAttributes?: React.ScriptHTMLAttributes; linkAttributes?: React.LinkHTMLAttributes; } export const VWOScript: React.FC = ({ accountId, type = 'ASYNC', settingsTimeout = 2000, hideElement = 'body', hideElementStyle = 'opacity:0 !important;filter:alpha(opacity=0) !important;background:none !important', scriptAttributes = {}, linkAttributes = {}, }) => { try { const scriptType = typeof type === 'string' ? type.toLowerCase() : 'async'; const smartCode = `window._vwo_code||(function(){var w=window,d=document;var account_id=${accountId},version=2.2,settings_tolerance=${settingsTimeout},hide_element='${hideElement}',hide_element_style='${hideElementStyle}';if(f=!1,v=d.querySelector('#vwoCode'),cc={},-1{var e={combination:[],combinationChoose:[],split:[],exclude:[],uuid:null,consent:null,optOut:null},t=d.cookie||'';if(t)for(var i,n,o=/(?:^|;\\s*)(?:(_vis_opt_exp_(\\d+)_combi=([^;]*))|(_vis_opt_exp_(\\d+)_combi_choose=([^;]*))|(_vis_opt_exp_(\\d+)_split=([^:;]*))|(_vis_opt_exp_(\\d+)_exclude=[^;]*)|(_vis_opt_out=([^;]*))|(_vwo_global_opt_out=[^;]*)|(_vwo_uuid=([^;]*))|(_vwo_consent=([^;]*)))/g;null!==(i=o.exec(t));)try{i[1]?e.combination.push({id:i[2],value:r(i[3])}):i[4]?e.combinationChoose.push({id:i[5],value:r(i[6])}):i[7]?e.split.push({id:i[8],value:r(i[9])}):i[10]?e.exclude.push({id:i[11]}):i[12]?e.optOut=r(i[13]):i[14]?e.optOut=!0:i[15]?e.uuid=r(i[16]):i[17]&&(n=r(i[18]),e.consent=n&&3<=n.length?n.substring(0,3):null)}catch(e){}return e})();function n(){var e=(()=>{if(w.VWO&&Array.isArray(w.VWO))for(var e=0;e{var e=[],t={};if(s&&s.combinationChoose)for(var i=0;i{var e={},t=[];if(w.VWO&&Array.isArray(w.VWO))for(var i=0;i{var e=[],t={};if(s&&s.exclude)for(var i=0;i ); } return ( <>