braze-inc / braze-web-sdk

Public repo for the Braze Web SDK
https://www.braze.com
Other
73 stars 25 forks source link

Question: `logCardClick` not updating cards (v2.4.1) #75

Closed asherstoppard closed 4 years ago

asherstoppard commented 4 years ago

Good Afternoon,

We're manually implementing Content Cards and we need to log click events. When firing a logCardClick with a card instance, we get a true response but it doesn't appear to actually update in Braze or in the card instance after a refresh.

I've tried multiple iterations but, for clarity, does the following example look correct?

const selectedCard = appboy.getCachedContentCards().cards[0]
appboy.logCardClick(selectedCard) // true
appboy.requestContentCardsRefresh()
appboy.getCachedContentCards() // .cards[0].clicked = false

Thank you for your help.

asherstoppard commented 4 years ago

Just for a little more clarity, I can see a 201 success response from /api/v3/data for the following payload:

{
  "respond_with": {
    "user_id": "__USER_ID__",
    "config": {
      "config_time": 1571422045
    }
  },
  "events": [
    {
      "name": "cc",
      "time": 1580828269.323,
      "data": {
        "ids": [
          "__CARD_ID__"
        ]
      },
      "session_id": "__SESSION_ID__",
      "user_id": "__USER_ID__"
    }
  ],
  "api_key": "__API_KEY__",
  "time": 1580828274,
  "sdk_version": "2.4.1",
  "device_id": "__DEVICE_ID__"
}
wesleyorbin commented 4 years ago

Hi @asherstoppard - thanks for reaching out! appboy.logCardClick queues up the click event to be sent to the /api/v3/data endpoint at a later time (about every 10 seconds). If you call appboy.requestImmediateDataFlush, you can force the click event to be pushed up to the backend immediately. After this call completes, you should then be able to refresh your Content Cards and see the logged click.

Do note, however, that appboy.requestContentCardsRefresh will not update the Content Cards cache until the network call has completed. You can use appboy.subscribeToContentCardsUpdates to subscribe to updates if you want to see the change immediately after it comes in.

Let me know if this solves your issue.

asherstoppard commented 4 years ago

Hi @wesleyorbin,

Thank's for getting back to me, I've just re-written a very rudimentary test to check the above instructions and I'm still getting the same results:

const selectedCard = appboy.getCachedContentCards().cards[0]
const callback = cards => console.log(cards)
appboy.subscribeToContentCardsUpdates(callback)
appboy.logCardClick(selectedCard) // true
appboy.requestImmediateDataFlush()
appboy.requestContentCardsRefresh() // cards[0].clicked = false
wesleyorbin commented 4 years ago

@asherstoppard When you call appboy.logCardClick, make sure that you're setting the forContentCards parameter to true since you're using Content Cards (e.g, appboy.logCardClick(selectedCard, true)). The same thing would apply for the logCardImpressions method as well.

asherstoppard commented 4 years ago

@wesleyorbin Ah good spot. I've made the change to logCardClick but I'm still unable to update the clicked parameter with the above test. Is there anything else I can try?

asherstoppard commented 4 years ago

So I can now see clicks registering in the campaign but they're not showing in the feed after requestContentCardsRefresh.

wesleyorbin commented 4 years ago

@asherstoppard After some further investigation, it does appear that there's a bug where a refresh will overwrite the local clicked value. We will have a fix out for this as soon as possible. Thank you again for reporting this and we'll get back to you when the fix has been released.

asherstoppard commented 4 years ago

@wesleyorbin No problem at all, I'll keep the issue open for tracking. Please let me know if there's anything I can help with :+1:

wesleyorbin commented 4 years ago

Hi @asherstoppard! We just released version 2.5.0, which includes a fix for this issue.

I'm going to close out this issue for now, but should you continue to experience issues after upgrading, please feel free to re-open.