diff --git a/assets/js/build/survey/survey_deps.asset.php b/assets/js/build/survey/survey_deps.asset.php index baba90f..2744d0f 100644 --- a/assets/js/build/survey/survey_deps.asset.php +++ b/assets/js/build/survey/survey_deps.asset.php @@ -1 +1 @@ - array(), 'version' => 'd18c4036e32153ba476c'); + array(), 'version' => 'c59f3ab226aad71e7c11'); diff --git a/assets/js/build/survey/survey_deps.js b/assets/js/build/survey/survey_deps.js index a071504..19670a3 100644 --- a/assets/js/build/survey/survey_deps.js +++ b/assets/js/build/survey/survey_deps.js @@ -1 +1 @@ -(()=>{"use strict";async function r(r){if(!window.formbricks){const o=await fetch(`${r}/api/packages/app`);if(!o.ok)return{ok:!1,error:new Error("Failed to load Formbricks App SDK")};const e=await o.text(),t=document.createElement("script");t.innerHTML=e,document.head.appendChild(t);const n=async()=>new Promise(((r,o)=>{const e=setInterval((()=>{window.formbricks&&(clearInterval(e),r())}),100);setTimeout((()=>{clearInterval(e),o(new Error("Formbricks App SDK loading timed out"))}),1e4)}));try{return await n(),{ok:!0,data:void 0}}catch(r){return{ok:!1,error:new Error(r.message??"Failed to load Formbricks App SDK")}}}return{ok:!0,data:void 0}}const o=new Proxy({},{get:(o,e,t)=>async(...o)=>{if(!window.formbricks){if("init"!==e)return void console.error("🧱 Formbricks - Global error: You need to call formbricks.init before calling any other method");if(!o[0])return void console.error("🧱 Formbricks - Global error: You need to pass the apiHost as the first argument");const{apiHost:n}=o[0],i=await(t=r,async(...r)=>{try{return{ok:!0,data:await t(...r)}}catch(r){return{ok:!1,error:r}}})(n);if(!i.ok)return void console.error(`🧱 Formbricks - Global error: ${i.error.message}`)}var t;if(window.formbricks&&"function"!=typeof window.formbricks[e])console.error(`🧱 Formbricks - Global error: Formbricks App SDK does not support method ${String(e)}`);else try{return window.formbricks[e](...o)}catch(r){return void console.error(`Something went wrong: ${r}`)}}});document.addEventListener("DOMContentLoaded",(()=>{window.tsdk_formbricks=o,window.dispatchEvent(new Event("themeisle:survey:loaded"))}))})(); \ No newline at end of file +(()=>{"use strict";let r=!1,i=!1;const o=[],t=new Proxy({},{get:(t,e,n)=>(...t)=>(async(t,e,...n)=>{if(i){if(window.formbricks){const r=t;await window.formbricks[r](...n)}}else if("init"===t){if(r)return void console.warn("🧱 Formbricks - Warning: Formbricks is already initializing.");r=!0;const t=n[0].apiHost,s=await(async(r,i)=>{if(!window.formbricks){const o=await fetch(`${r}/api/packages/${i}`);if(!o.ok)return{ok:!1,error:new Error(`Failed to load Formbricks ${i} SDK`)};const t=await o.text(),e=document.createElement("script");e.innerHTML=t,document.head.appendChild(e);const n=async()=>new Promise(((r,o)=>{const t=setInterval((()=>{window.formbricks&&(clearInterval(t),r())}),100);setTimeout((()=>{clearInterval(t),o(new Error(`Formbricks ${i} SDK loading timed out`))}),1e4)}));try{return await n(),{ok:!0,data:void 0}}catch(r){return{ok:!1,error:new Error(r.message??`Failed to load Formbricks ${i} SDK`)}}}return{ok:!0,data:void 0}})(t,e);if(s.ok&&window.formbricks){window.formbricks.init(...n),r=!1,i=!0;for(const{prop:r,args:i}of o)"function"==typeof window.formbricks[r]?window.formbricks[r](...i):console.error(`🧱 Formbricks - Error: Method ${r} does not exist on formbricks`)}}else console.warn("🧱 Formbricks - Warning: Formbricks not initialized. This method will be queued and executed after initialization."),o.push({prop:t,args:n})})(e,"app",...t)});document.addEventListener("DOMContentLoaded",(()=>{window.tsdk_formbricks={init:r=>{"object"==typeof r.attributes&&(r.attributes={...window.tsdk_survey_attrs,...r.attributes}),t?.init(r)}},window.dispatchEvent(new Event("themeisle:survey:loaded"))}))})(); \ No newline at end of file diff --git a/assets/js/src/survey_deps.js b/assets/js/src/survey_deps.js index 15e5b85..9b6b977 100644 --- a/assets/js/src/survey_deps.js +++ b/assets/js/src/survey_deps.js @@ -5,6 +5,18 @@ import formbricks from "@formbricks/js/app"; * Emit a custom event to let other scripts know that formbricks is loaded. */ document.addEventListener("DOMContentLoaded", () => { - window.tsdk_formbricks = formbricks; + window.tsdk_formbricks = { + init: (args) => { + if ( typeof args.attributes === 'object' ) { + args.attributes = { + ...window.tsdk_survey_attrs, + ...args.attributes + } + } + + formbricks?.init(args) + } + }; + window.dispatchEvent(new Event("themeisle:survey:loaded")); }); diff --git a/package-lock.json b/package-lock.json index 1c8b77d..915f310 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,14 +1,14 @@ { "name": "themeisle-sdk", - "version": "3.3.29", + "version": "3.3.31", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "themeisle-sdk", - "version": "3.3.29", + "version": "3.3.31", "dependencies": { - "@formbricks/js": "^2.0.0", + "@formbricks/js": "^2.2.0", "object-hash": "^3.0.0" }, "devDependencies": { @@ -2241,9 +2241,13 @@ } }, "node_modules/@formbricks/js": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@formbricks/js/-/js-2.0.0.tgz", - "integrity": "sha512-1T0i1zxU3cKDQ3Rxw9DXGoWwLNBEJT2pO2ELuwbGg36u6ijazLA4j61HbNUMuHgEoiyhVtLcTOZF5FquQVzr/A==" + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/@formbricks/js/-/js-2.2.0.tgz", + "integrity": "sha512-sKduJRgMZInOY141tIQN6RSsA4Wah6liqzCDDdGgv9t2FgTaNjSYGNrLlBEdQN62lRbVm5dk0+ZzMWyYrNhZWw==", + "license": "MIT", + "peerDependencies": { + "zod": "3.x" + } }, "node_modules/@hapi/hoek": { "version": "9.3.0", @@ -27579,6 +27583,16 @@ "funding": { "url": "https://github.com/sponsors/sindresorhus" } + }, + "node_modules/zod": { + "version": "3.23.8", + "resolved": "https://registry.npmjs.org/zod/-/zod-3.23.8.tgz", + "integrity": "sha512-XBx9AXhXktjUqnepgTiE5flcKIYWi/rme0Eaj+5Y0lftuGBq+jyRu/md4WnuxqgP1ubdpNCsYEYPxrzVHD8d6g==", + "license": "MIT", + "peer": true, + "funding": { + "url": "https://github.com/sponsors/colinhacks" + } } } } diff --git a/package.json b/package.json index 3dc3f62..03c9d70 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "semantic-release": "^17.4.7" }, "dependencies": { - "@formbricks/js": "^2.0.0", + "@formbricks/js": "^2.2.0", "object-hash": "^3.0.0" } } diff --git a/src/Modules/Script_loader.php b/src/Modules/Script_loader.php index 8d37c43..38b131b 100644 --- a/src/Modules/Script_loader.php +++ b/src/Modules/Script_loader.php @@ -121,6 +121,15 @@ public function load_survey( $handler ) { $asset_file['version'], true ); + + $language = get_user_locale(); + $available_languages = [ + 'de_DE' => 'de', + 'de_DE_formal' => 'de', + ]; + $lang_code = isset( $available_languages[ $language ] ) ? $available_languages[ $language ] : 'en'; + + wp_localize_script( $handler, 'tsdk_survey_attrs', [ 'language' => $lang_code ] ); } /**