PageSourceSearch

https://app.addsearch.com/assets/AdvancePersonalization-BUx9HOH3.js

js addsearch.com collected 2026-10-02 02:19:19 UTC 18,340 bytes, 1 lines download raw bytes

1import{j as e}from"./jsx-runtime-D_zvdyIk.js";import{a as o}from"./index-BOFepIoo.js";import{u as _}from"./useQuery-Cgvym9xc.js";import{u as de}from"./utils-CjpktROR.js";import{j as A,z as ue,F as q,H as I,B as E,I as Q,q as me,L as xe}from"./AppRouter-BZy88VzR.js";import{S as he}from"./SliderField-CYlMzxVh.js";import{C as Y}from"./Card-DJSQZwwX.js";import{A as D}from"./Alert-B3SzZIai.js";import{P as U}from"./PageHeader-CgOT2X-q.js";import{T as fe}from"./Toggle-BmcvC6JF.js";import"./useBaseQuery--CRDVBp_.js";import"./lib-vye-0uEl.js";import"./DashboardConfigContext-BjZhgoRF.js";import"./index-DsYStbZt.js";import"./bundle-mjs-C6Cmh_M-.js";import"./ErrorFallback-vy0iYigB.js";import"./ErrorBoundary-rGAtuFEK.js";const pe=async t=>{const{data:s}=await A.get(`/admin/sites/${t}/settings/site-settings`);return s},ge=async t=>{const{data:s}=await A.get(`/admin/sites/${t}/settings/site-settings:default`);return s},ve=async(t,s)=>{const{data:i}=await A.post(`/admin/sites/${t}/settings/site-settings`,s);return i},ye=async t=>{const{data:s}=await A.get(`/admin/sites/${t}/custom-fields`);return s},je=async(t,s,i,n)=>{const{data:a}=await A.post(`/admin/sites/${t}/search`,{term:s||"*",...i?{userToken:i}:{},...n?{disablePersonalization:!0}:{},paging:{page:1,pageSize:20}});return a},b={fetchConfig:pe,fetchDefaults:ge,saveConfig:ve,fetchCustomFields:ye,searchPreview:je},X=o.createContext(void 0);function be(t){return t?Object.entries(t).filter(([,s])=>s==="text"||s==="keyword").map(([s])=>s):[]}function we(t,s,i){const n=new Map;for(const a of t??[]){const c=a.field.replace("custom_fields.","");n.set(c,a.boost)}return s.map(a=>({customFieldName:a,boostValue:n.get(a)??i}))}function Ce(t,s){const i=new Map;let n=0;for(const c of(t==null?void 0:t.personalizationRules)??[]){const d=c.field.replace("custom_fields.","");d==="custom_fields"||d===""?n=c.boost:i.set(d,c.boost)}const a={};for(const c of s)a[c]=i.get(c)??n;return a}const Ne=({siteKey:t,site:s,dashboardConfig:i,children:n})=>{var O,$,H;const a=de(),{features:c}=ue(),d=c??{},[f,r]=o.useState(!1),[x,u]=o.useState(),[v,p]=o.useState(!1),w=!!d["settings.personalization"],m=(s==null?void 0:s.customerType)==="SHOPIFY",l=!!(i!=null&&i.sampleIndexKey&&(s==null?void 0:s.id)===i.sampleIndexKey),{data:h,isLoading:G,isError:J}=_({queryKey:["advancePersonalization","config",t],queryFn:()=>b.fetchConfig(t),staleTime:300*1e3,retry:2,throwOnError:!1}),{data:P,isLoading:K,isError:ee}=_({queryKey:["advancePersonalization","defaults",t],queryFn:()=>b.fetchDefaults(t),staleTime:600*1e3,retry:2,throwOnError:!1}),{data:M,isLoading:te,isError:se}=_({queryKey:["advancePersonalization","customFields",t],queryFn:()=>b.fetchCustomFields(t),staleTime:300*1e3,retry:2,throwOnError:!1}),ae=G||K||te,ie=J||ee||se,k=!!((O=h==null?void 0:h.personalizationByStatistics)!=null&&O.active),R=be(M),ne=((H=($=P==null?void 0:P.personalizationRules)==null?void 0:$.find(j=>j.field==="custom_fields"||j.field===""))==null?void 0:H.boost)??0,re=we(h==null?void 0:h.personalizationRules,R,ne),T=Ce(P,R),C=["advancePersonalization","config",t],N=o.useCallback(async()=>{await a.invalidateQueries({queryKey:[...C]})},[a,C]),oe=o.useCallback(async j=>{var g;if(j){r(!0),u(void 0);try{const S=!k,z=a.getQueryData([...C]),L={personalizationByStatistics:{active:S,daysInterval:((g=z==null?void 0:z.personalizationByStatistics)==null?void 0:g.daysInterval)??30}};await b.saveConfig(t,L),await N(),q("Personalization: Setting Toggled",t,{action:S?"Enabled":"Disabled"})}catch{u("Failed to toggle personalization"),await N()}finally{r(!1)}}},[t,k,a,C,N]),le=o.useCallback(async j=>{r(!0),u(void 0);try{const g=a.getQueryData([...C]),S=new Map;for(const y of(g==null?void 0:g.personalizationRules)??[]){const F=y.field.replace("custom_fields.","");S.set(F,y.boost)}for(const[y,F]of Object.entries(j))S.set(y,F);const z=[];for(const[y,F]of S.entries())y==="custom_fields"||y===""||z.push({field:`custom_fields.${y}`,boost:F,action:"click"});const L={personalizationByStatistics:(g==null?void 0:g.personalizationByStatistics)??{active:k,daysInterval:30},personalizationRules:z};await b.saveConfig(t,L),await N(),p(!1),q("Personalization: Events Configured",t,{changed_field_count:Object.keys(j).length})}catch{u("Failed to save personalization settings"),await N()}finally{r(!1)}},[t,k,a,C,N]),ce=o.useCallback(()=>({...T}),[T]);return e.jsx(X.Provider,{value:{siteKey:t,site:s,dashboardConfig:i,config:h,defaults:P,customFields:M,displayScores:re,defaultScores:T,isLoading:ae,isSaving:f,error:x,loadFailed:ie,hasAccess:w,isShopify:m,isSampleIndex:l,features:d,isActive:k,isEditing:v,setIsEditing:p,togglePersonalization:oe,saveScores:le,restoreDefaults:ce},children:n})},B=()=>{const t=o.useContext(X);if(t===void 0)throw new Error("useAdvancePersonalizationContext must be used within an AdvancePersonalizationProvider");return t},V=0,Z=20,Se=()=>e.jsx("svg",{width:"21",height:"21",viewBox:"0 0 21 21",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:e.jsx("path",{d:"M10.0984 16.2109C8.49844 16.1276 7.14844 15.5109 6.04844 14.3609C4.94844 13.2109 4.39844 11.8276 4.39844 10.2109C4.39844 8.54427 4.98177 7.1276 6.14844 5.96094C7.3151 4.79427 8.73177 4.21094 10.3984 4.21094C12.0151 4.21094 13.3984 4.76094 14.5484 5.86094C15.6984 6.96094 
116.3151 8.31094 16.3984 9.91094L14.2984 9.28594C14.0818 8.38594 13.6151 7.6486 12.8984 7.07394C12.1818 6.4986 11.3484 6.21094 10.3984 6.21094C9.29844 6.21094 8.35677 6.6026 7.57344 7.38594C6.7901 8.16927 6.39844 9.11094 6.39844 10.2109C6.39844 11.1609 6.6861 11.9943 7.26144 12.7109C7.8361 13.4276 8.57344 13.8943 9.47344 14.1109L10.0984 16.2109ZM18.5734 20.3609L14.6484 16.4359L13.8984 18.7109C13.8151 18.9443 13.6568 19.0566 13.4234 19.0479C13.1901 19.0399 13.0318 18.9193 12.9484 18.6859L10.6734 11.1109C10.6068 10.9276 10.6484 10.7609 10.7984 10.6109C10.9484 10.4609 11.1151 10.4193 11.2984 10.4859L18.8734 12.7609C19.1068 12.8443 19.2278 13.0026 19.2364 13.2359C19.2444 13.4693 19.1318 13.6276 18.8984 13.7109L16.6234 14.4609L20.5484 18.3859C20.6484 18.4859 20.6984 18.6026 20.6984 18.7359C20.6984 18.8693 20.6484 18.9859 20.5484 19.0859L19.2734 20.3609C19.1734 20.4609 19.0568 20.5109 18.9234 20.5109C18.7901 20.5109 18.6734 20.4609 18.5734 20.3609Z",fill:"currentColor"})}),ze=({score:t,defaultValue:s,isEditMode:i,onValueChanged:n})=>e.jsx(he,{label:t.customFieldName,testId:t.customFieldName,value:t.boostValue,min:V,max:Z,step:1,disabled:!i,showInput:!0,allowMaxExtension:!1,clampValue:a=>Math.min(Z,Math.max(V,a)),onChange:a=>
1n(t.customFieldName,a),labelAccessory:i?e.jsxs("span",{className:"text-xs text-text-tertiary",title:`Default: ${s}`,children:["(default: ",s,")"]}):void 0}),Pe=()=>{const{displayScores:t,defaultScores:s,isEditing:i,setIsEditing:n,isSaving:a,error:c,saveScores:d,restoreDefaults:f}=B(),[r,x]=o.useState({}),u=o.useCallback((m,l)=>{x(h=>({...h,[m]:l}))},[]),v=o.useCallback(async()=>{await d(r),x({})},[d,r]),p=o.useCallback(()=>{n(!1),x({})},[n]),w=o.useCallback(()=>{const m=f();x(m)},[f]);return e.jsx(Y,{"data-testid":"configure-events",children:e.jsxs("div",{className:"flex flex-col gap-4 p-4",children:[e.jsx(I,{level:"card",as:"h3",className:"text-text-primary",children:"Configure Events"}),e.jsxs("div",{className:"flex items-center gap-2 text-text-secondary",children:[e.jsx(Se,{}),e.jsx("span",{className:"text-sm font-medium",children:"User clicked a search result"})]}),e.jsxs("p",{className:"text-sm text-text-tertiary",children:["Prioritize similar results to the ones that the user clicked before, based on the value of the following fields."," ",e.jsx("strong",{children:"Fields that contain numeric value are not shown as it's not supported by personalization."})]}),c&&e.jsx(D,{type:"error","data-testid":"configure-events-error",children:c}),e.jsxs("div",{className:"flex flex-col gap-1",children:[t.map(m=>e.jsx(ze,{score:r[m.customFieldName]!==void 0?{...m,boostValue:r[m.customFieldName]}:m,defaultValue:s[m.customFieldName]??0,isEditMode:i,onValueChanged:u},m.customFieldName)),t.length===0&&e.jsx("p",{className:"text-sm text-text-tertiary py-2","data-testid":"no-fields",children:"No text or keyword custom fields available for personalization."})]}),t.length>0&&e.jsx("div",{className:"flex items-center gap-2",children:i?e.jsxs(e.Fragment,{children:[e.jsx(E,{buttonStyle:"secondary",onClick:p,disabled:a,"data-testid":"cancel-button",children:"Cancel"}),e.jsx(E,{buttonStyle:"primary",onClick:()=>{v()},disabled:a,"data-testid":"save-button",children:a?"Saving...":"Save"}),e.jsx(E,{buttonStyle:"secondary",onClick:w,disabled:a,"data-testid":"restore-defaults-button",children:"Restore to default"})]}):e.jsx(E,{buttonStyle:"secondary",onClick:()=>n(!0),"data-testid":"edit-button",children:"Edit"})})]})})},ke=()=>e.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:e.jsx("path",{d:"M11 17h2v-6h-2v6Zm1-8q.425 0 .713-.288T13 8q0-.425-.288-.712T12 7q-.425 0-.712.288T11 8q0 .425.288.713T12 9Zm0 13q-2.075 0-3.9-.788-1.825-.787-3.175-2.137T2.788 15.9 2 12t.788-3.9q.787-1.825 2.137-3.175T8.1 2.788 12 2t3.9.788q1.825.787 3.175 2.137T21.213 8.1 22 12t-.788 3.9q-.787 1.825-2.137 3.175T15.9 21.213 12 22Z",fill:"#B2B2B2"})}),W=({hit:t,isShopify:s})=>{var n,a;const i=s?((n=t.custom_fields)==null?void 0:n.product_title)??t.title:t.title;return e.jsxs("div",{className:"flex gap-3 rounded-md border border-border-default bg-white p-3",children:[((a=t.images)==null?void 0:a.main)&&e.jsxs("div",{className:"flex flex-col items-center gap-1",children:[e.jsx("div",{className:"h-16 w-16 overflow-hidden rounded-md bg-bg-surface-disabled",children:e.jsx("img",{src:t.images.main,alt:"",className:"h-full w-full object-cover",onError:c=>{c.target.style.display="none"}})}),e.jsx("span",{className:"text-xs font-semibold text-text-tertiary",children:t.score.toFixed(2)})]}),e.jsxs("div",{className:"flex flex-col gap-0.5 overflow-hidden",children:[e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",className:"truncate text-xs text-primary hover:underline",children:t.url}),e.jsx("span",{className:"text-sm font-semibold text-text-primary truncate",children:i}),e.jsxs("span",{className:"text-xs text-text-tertiary italic",children:["Document ID: ",t.id]})]})]})},Fe=()=>{const{siteKey:t,isShopify:s}=B(),[i,n]=o.useState(""),[a,c]=o.useState(""),[d,f]=o.useState([]),[r,x]=o.useState(null),[u,v]=o.useState(null),[p,w]=o.useState(!1),m=o.useCallback(async()=>{if(i.trim()){w(!0);try{const l=await b.searchPreview(t,i,void 0,!0);if(f(l.hits??[]),v(l.total_hits??0),q("Personalization: Changes Previewed",t,{is_previewed_for_user:!!a.trim(),result_count:l.total_hits??0}),a.trim()){const h=await b.searchPreview(t,i,a,!1);x(h.hits??[])}else x(null)}catch(l){console.error("Search preview failed:",l),f([]),x(null),v(null)}finally{w(!1)}}},[t,i,a]);return e.jsx(Y,{"data-testid":"search-preview",children:e.jsxs("div",{className:"flex flex-col gap-4 p-4",children:[e.jsx(I,{level:"card",as:"h3",className:"text-text-primary",children:"Preview Changes"}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"text-sm text-text-secondary",htmlFor:"personalization-user-id",children:"Preview personalized results for a specific user:"}),e.jsx(Q,{id:"personalization-user-id",value:a,onChange:l=>c(l.target.value),placeholder:"Enter a User ID","data-testid":"user-id-input"})]}),e.jsxs("form",{onSubmit:l=>{l.preventDefault(),m()},className:"flex items-center gap-2",children:[e.jsx(Q,{value:i,onChange:l=>n(l.target.value),placeholder:"Enter search term",className:"flex-1","data-testid":"search-term-input"}),e.jsx(E,{buttonStyle:"primary",type:"submit",disabled:p,"data-testid":"search-button",children:p?"Searching...":"Search"})]}),u!==null&&e.jsxs("p",{className:"text-sm text-text-secondary","data-testid":"results-count",children:["Showing ",d.length," results ",e.jsx("strong",{children:"without personalization"})," — ",(r==null?void 0:r.length)??0," ",((r==null?void 0:r.length)??0)===1?"result":"results"," ",e.jsx("strong",{children:"with personalization"})," of ",u," total"]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(I,{level:"sidebar",as:"h4",className:"text-text-secondary",children:"Without Personalization"}),d.length>0?e.jsx("div",{className:"flex flex-col gap-2 max-h-[500px] overflow-y-auto",children:d.map(l
1=>e.jsx(W,{hit:l,isShopify:s},l.id))}):u!==null&&e.jsx("p",{className:"text-sm text-text-tertiary py-4 text-center",children:"No results"})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(I,{level:"sidebar",as:"h4",className:"text-text-secondary",children:"With Personalization"}),r===null?e.jsxs("div",{className:"flex flex-col items-center justify-center gap-3 py-8 text-text-tertiary","data-testid":"no-user-id-message",children:[e.jsx(ke,{}),e.jsx("p",{className:"text-sm text-center",children:"Enter a user ID in the filter on the top to see the personalized results."})]}):r.length>0?e.jsx("div",{className:"flex flex-col gap-2 max-h-[500px] overflow-y-auto",children:r.map(l=>e.jsx(W,{hit:l,isShopify:s},l.id))}):e.jsx("p",{className:"text-sm text-text-tertiary py-4 text-center",children:"No results"})]})]})]})})},Ee=({open:t,onClose:s,onConfirm:i,isShopify:n})=>e.jsx(me,{open:t,onClose:s,title:"Enabling Personalization",width:"md",footer:e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:s,className:"px-4 py-2 text-sm font-semibold rounded-md border border-border-strong text-text-secondary bg-bg-surface hover:bg-bg-surface-hover","data-testid":"consent-cancel-button",children:"Cancel"}),e.jsx("button",{type:"button",onClick:i,className:"px-4 py-2 text-sm font-semibold rounded-md bg-primary text-text-on-primary hover:opacity-80","data-testid":"consent-agree-button",children:"Agree & Continue"})]}),children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx("p",{className:"text-sm text-text-secondary",children:"By enabling this feature, you agree to let AddSearch collect and analyse data on how your website visitors interact with search results by relating their search click events to them."}),e.jsx("p",{className:"text-sm text-text-secondary",children:"To do this, we will store a cookie on the devices of your website visitors that contains an identifier that allows to track user's searches and clicks."}),n&&e.jsxs(e.Fragment,{children:[e.jsx(I,{level:"sidebar",as:"h4",className:"text-text-primary",children:"Important: For Shopify Users"}),e.jsx("p",{className:"text-sm text-text-secondary",children:'Please verify your "Customer Privacy" settings in the Shopify admin area. Navigate to "Online Store" and then select "Preferences." If the "Customer Privacy" is configured to "Collect after consent," you must implement a cookie management solution on your Shopify website. This is a mandatory prerequisite for the personalization features to function correctly.'})]}),e.jsxs("p",{className:"text-xs text-text-tertiary",children:["Please read our"," ",e.jsx("a",{href:"https://www.addsearch.com/privacy/",target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline",children:"Privacy Policy"})," ","to learn more about how we use and protect your data and that of your site visitors."]})]})}),Ie=()=>{const{isLoading:t,error:s,loadFailed:i,hasAccess:n,isActive:a,isShopify:c,isSampleIndex:d,isSaving:f,togglePersonalization:r}=B(),[x,u]=o.useState(!1),v=o.useCallback(()=>{a?r(!0):u(!0)},[a,r]),p=o.useCallback(()=>{u(!1),r(!0)},[r]);return n?t?e.jsxs("div",{className:"flex items-center justify-center py-12","data-testid":"advance-personalization-loading",children:[e.jsx(xe,{size:8}),e.jsx("span",{className:"ml-3 text-text-tertiary",children:"Loading personalization settings..."})]}):i?e.jsx(D,{type:"error","data-testid":"advance-personalization-error",children:s||"Failed to load personalization settings. Please reload the page."}):e.jsxs("div",{className:"flex flex-col gap-6","data-testid":"advance-personalization",children:[e.jsx(U,{title:"Personalization",description:"The personalization feature ensures that users find the most relevant results based on their behaviour data. For example: a user that clicked on certain results in a search will get similar items prioritized in subsequent searches automatically. You can control here what kind of fields related to search result items are prioritized when it comes to finding similarities between search results and then preview how the results are affected for specific users."}),!c&&!d&&e.jsxs(D,{type:"info","data-testid":"implementation-info",children:["Personalization feature needs to be enabled or implemented in your installation. Check the"," ",e.jsx("a",{href:"https://www.addsearch.com/docs/result-management/implementing-personalization/",target:"_blank",rel:"noopener noreferrer",className:"text-primary font-semibold hover:underline",children:"documentation"})," ","for more information."]}),e.jsxs("div",{className:"flex items-center gap-3","data-testid":"activation-bar",children:[e.jsx(fe,{isChecked:a,onChange:v,disabled:f,ariaLabel:"Activate Personalization","data-testid":"personalization-toggle"}),e.jsx("span",{className:"text-body-sm font-medium text-text-primary",children:"Activate Personalization"}),a&&e.jsx("span",{className:"text-caption text-success-text font-medium",children:"Active"})]}),e.jsx("div",{className:`relative ${a?"":"opacity-50 pointer-events-none"}`,"data-testid":"configuration-panel",children:e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsx(Pe,{}),e.jsx(Fe,{})]})}),e.jsx(Ee,{open:x,onClose:()=>u(!1),onConfirm:p,isShopify:c})]}):e.jsxs("div",{className:"flex flex-col gap-6","data-testid":"advance-personalization-upgrade",children:[e.jsx(U,{title:"Personalization",description:"Upgrade your plan to access the personalization feature."}),e.jsx(D,{type:"info",children:e.jsx("a",{href:"https://www.addsearch.com/pricing/",target:"_blank",rel:"noopener noreferrer",className:"text-primary font-semibold hover:underline",children:"Upgrade Plan To Activate"})})]})},Ye=({siteKey:t,site:s,dashboardConfig:i})=>e.jsx(Ne,{siteKey:t,site:s,dashboardConfig:i,children:e.jsx(Ie,{})});
1export{Ye as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.