By default, the user ID is the user’s IP address.
For more accurate analytics, explicitly set a user token
Query aggregation and backend search
If you make search requests from your backend,
the user ID for all searches would be your server’s IP address,
which leads to inaccurate analytics.
To obtain accurate analytics, you must provide unique user IDs.
To provide unique user IDs, select one of these options:
If you make search requests from your backend servers,
and you don’t want to explicitly set user tokens,
you can add the X-Forwarded-For header to forward your users’ IP addresses to Algolia.
$res=$index->search('',[// Replace `XX.XXX.XXX.XXXX` with your user's IP address'X-Forwarded-For'=>'XX.XXX.XXX.XXX',]);
1
2
3
4
5
6
res=index.search('',{headers: {# Replace `XX.XXX.XXX.XXXX` with your user's IP address'X-Forwarded-For':'XX.XXX.XXX.XXX'}})
1
2
3
4
5
6
7
8
index.search('',{headers:{// Replace `XX.XXX.XXX.XXXX` with your user's IP address'X-Forwarded-For':'XX.XXX.XXX.XXX',},}).then(({hits})=>{console.log(hits);});
1
2
3
4
res=index.search("",{# Replace `XX.XXX.XXX.XXXX` with your user's IP address
"X-Forwarded-For":"XX.XXX.XXX.XXX",})
1
2
3
4
5
6
7
8
9
10
11
12
13
14
letrequestOptions=RequestOptions()// Replace `XX.XXX.XXX.XXXX` with your user's IP addressrequestOptions.headers["X-Forwarded-For"]="XX.XXX.XXX.XXX"index.search(Query(query:""),requestOptions:requestOptions,completionHandler:{(content,error)->Voidiniferror==nil{print("Result: \(content!)")}})
1
2
3
4
5
6
7
valquery=Query("")valrequestOptions=requestOptions{// Replace `XX.XXX.XXX.XXXX` with your user's IP addressheader("X-Forwarded-For","XX.XXX.XXX.XXX")}index.search(query,requestOptions)
1
2
3
4
5
6
7
RequestOptionsrequestOptions=newRequestOptions{// Replace `XX.XXX.XXX.XXXX` with your user's IP addressHeaders=newDictionary<string,string>{{"X-Forwarded-For","XX.XXX.XXX.XXX"}}};varresult=index.Search<T>(newQuery(""),requestOptions);
1
2
3
4
5
index.search(newQuery(""),// Replace `XX.XXX.XXX.XXXX` with your user's IP addressnewRequestOptions().addExtraHeader("X-Forwarded-For","XX.XXX.XXX.XXX"));
1
2
3
4
5
6
// Replace `XX.XXX.XXX.XXXX` with your user's IP addressextraHeaders:=opt.ExtraHeaders(map[string]string{"X-Forwarded-For":"XX.XXX.XXX.XXX",})res,err=index.Search("",extraHeaders)
1
2
3
4
5
6
7
8
client.execute{searchinto"YourIndexName"queryQuery(query=Some(""))optionsRequestOptions(// Replace `XX.XXX.XXX.XXXX` with your user's IP addressextraHeaders=Some(Map("X-Forwarded-For"=>"XX.XXX.XXX.XXX")))}