<@U01PL2YSG8L> we trying to implement analytics ex...
# community-help
a
@Kishore Nallan we trying to implement analytics export const sendClickEvent = async (bookId, user_id = null) => { alert("event tracked") try { const event = { name*:* "book_clicks"*,* event_type*:* "click"*,* data*:* { doc_id*:* `${bookId}`*,* user_id*:* `${user_id}`*,* } }*;* const resp = client*.analytics.events().*create(event) } catch (error) { console*.error("Error sending click event:",* error)*;* } from reacts but it reveal admin key on dev tools what should be best pratice
f
Hey Akash, You'll have to create a key that only has the ability to send analytic events. Here're some docs
a
curl -X POST "https://ew5h2tr67livkp41p-1.a1.typesense.net/keys" \ -H "X-TYPESENSE-API-KEY: YOUR_ADMIN_KEY" \ -H "Content-Type: application/json" \ -d '{ "description": "Analytics Events Key", "actions": ["analytics:create"], "collections": ["books_collection"] }' key is generated by this but still getting 401 Unauthorized
f
Can you try adding
analytics/events:create
to the list? Also, if there's still an issue, make sure that both the collection being search and the collection being updated are part of the
collections
property
a
{ "description": "Analytics Events Key v3", "actions": ["analytics/events:create"], "collections": ["books_collection"] } still facing same issue 401 and schema is { "facet": false, "index": true, "infix": false, "locale": "", "name": "popularity", "optional": true, "sort": true, "stem": false, "stem_dictionary": "", "store": true, "truncate_len": 100, "type": "int32" } present in schema of books_collection
f
Are you self-hosting or on Typesense cloud?
a
we are using Typesense cloud
f
Sorry, what does no refer to in this context?
a
we are using Typesense cloud hosting
f
Could you share your cluster's id?
a
ew5h2tr67livkp41p
are you there @Fanis Tharropoulos
please update on this
@Fanis Tharropoulos
hi @Fanis Tharropoulos
f
Hey Akash, Using a key like this one:
Copy code
{
  "description": "Typesense team debug key",
  "actions": [
    "analytics/events:create"
  ],
  "collections": [
    "books_collection"
  ]
}
works just fine using curl directly on my testing. Have you tried one like this?