exponea / exponea-ios-sdk

MIT License
19 stars 27 forks source link

Push Token not setting in Exponea but SDK is sending it #19

Closed jackjpark closed 3 years ago

jackjpark commented 3 years ago

Hi,

Im moving from the automatic swizzling handling of notifications to the new method using ExponeaAppDelegate

In the logging i see:

2020-09-10 05:23:29374 ExponeaSDK ℹ️ VERBOSE [TrackingManager.swift]:184 track(_:with:): Tracking event of type: registerPushToken with params [ExponeaSDK.DataType.pushNotificationToken(token: Optional("TOKENSTRING"), authorized: true)]

However in exponea the userID has no token. Please can you advise what could be wrong here, I dont see any errors...

All other tracking and events are visible in exponea, its just not adding the push token...

wassil commented 3 years ago

Hi, the log that you pasted in your question is produced when tracking of the event starts. Next, we pick a project token(if you're using projectMapping, I'd check that). Event with project token is then written into internal database of the application. Last step is flushing the event to Exponea servers. If you're using .immediate flushMode, flushing should happen right after the event is tracked. This is what you should see in the logs:

2020-09-11 09:38:26489 ExponeaSDK ℹ️ VERBOSE [RequestFactory.swift]:81 prepareRequest(parameters:customerIds:): Created request: 
[Request]
POST https://cloud-api.exponea.com/track/v2/projects/f3a64f78-c27c-11e9-8a72-f69eea2c8d5c/customers
Content-Type: application/json
Accept: application/json
Authorization: REDACTED
HTTP Body:
{
  "customer_ids" : {
    "cookie" : "BE8F530F-34D4-435A-AA85-CA989F3AC09E"
  },
  "properties" : {
    "apple_push_notification_id" : "REDACTED MY REAL TOKEN",
    "apple_push_notification_authorized" : true
  },
  "timestamp" : 1599809903.2902641
}

2020-09-11 09:38:27380 ExponeaSDK ℹ️ VERBOSE [RequestFactory.swift]:145 process(_:data:error:resultAction:): Response received:
[Response]
HTTP 200 https://cloud-api.exponea.com/track/v2/projects/f3a64f78-c27c-11e9-8a72-f69eea2c8d5c/customers/events
Date: Fri, 11 Sep 2020 07:38:26 GMT
access-control-allow-credentials: true
Via: 1.1 google
Content-Type: application/json
Access-Control-Allow-Origin: *
x-request-id: 02a2c841-5d98-4c74-bb87-df4dcfc8d8e0
alt-svc: clear
Content-Length: 29
Response Body:
{"success":true,"errors":[]}

Request contains apple_push_notification_id which is the name of customer property that holds push token. Check that response is successful, and that request was created at all. If not, I'd double check flushMode setting. If you can see the request and response is successful, the issue might be on the server.

jackjpark commented 3 years ago

Hi, the log that you pasted in your question is produced when tracking of the event starts. Next, we pick a project token(if you're using projectMapping, I'd check that). Event with project token is then written into internal database of the application. Last step is flushing the event to Exponea servers. If you're using .immediate flushMode, flushing should happen right after the event is tracked. This is what you should see in the logs:

2020-09-11 09:38:26489 ExponeaSDK ℹ️ VERBOSE [RequestFactory.swift]:81 prepareRequest(parameters:customerIds:): Created request: 
[Request]
POST https://cloud-api.exponea.com/track/v2/projects/f3a64f78-c27c-11e9-8a72-f69eea2c8d5c/customers
Content-Type: application/json
Accept: application/json
Authorization: REDACTED
HTTP Body:
{
  "customer_ids" : {
    "cookie" : "BE8F530F-34D4-435A-AA85-CA989F3AC09E"
  },
  "properties" : {
    "apple_push_notification_id" : "REDACTED MY REAL TOKEN",
    "apple_push_notification_authorized" : true
  },
  "timestamp" : 1599809903.2902641
}

2020-09-11 09:38:27380 ExponeaSDK ℹ️ VERBOSE [RequestFactory.swift]:145 process(_:data:error:resultAction:): Response received:
[Response]
HTTP 200 https://cloud-api.exponea.com/track/v2/projects/f3a64f78-c27c-11e9-8a72-f69eea2c8d5c/customers/events
Date: Fri, 11 Sep 2020 07:38:26 GMT
access-control-allow-credentials: true
Via: 1.1 google
Content-Type: application/json
Access-Control-Allow-Origin: *
x-request-id: 02a2c841-5d98-4c74-bb87-df4dcfc8d8e0
alt-svc: clear
Content-Length: 29
Response Body:
{"success":true,"errors":[]}

Request contains apple_push_notification_id which is the name of customer property that holds push token. Check that response is successful, and that request was created at all. If not, I'd double check flushMode setting. If you can see the request and response is successful, the issue might be on the server.

Hi ive had a look through the requests and seems like theres some sort of error going on, here is the customer call you showed in your response

POST https://api.exponea.com/track/v2/projects/d47ab19e-2af0-11e9-81cd-0a580a204889/customers
Accept: application/json
Content-Type: application/json
Authorization: REDACTED
HTTP Body:
{
  "customer_ids" : {
    "registered" : "1644649",
    "cookie" : "0E1895C6-158E-4444-B7F1-BC577DDA94EB"
  },
  "properties" : {
    "apple_push_notification_id" : "PUSH TOKEN",
    "apple_push_notification_authorized" : true
  },
  "timestamp" : 1599812555.628473
}
2020-09-11 09:22:38925 ExponeaSDK ℹ️ VERBOSE [RequestFactory.swift]:145 process(_:data:error:resultAction:): Response received:
[Response]
HTTP 403 https://api.exponea.com/track/v2/projects/d47ab19e-2af0-11e9-81cd-0a580a204889/customers
x-request-id: 6841b5a2-641a-4307-b03f-d2ac874d6f96
Access-Control-Allow-Origin: *
Date: Fri, 11 Sep 2020 08:22:38 GMT
Content-Type: application/json
alt-svc: clear
Content-Length: 86
Via: 1.1 google
access-control-allow-credentials: true
Response Body:
{"success":false,"errors":["not authorized to update specified customer properties"]}

as you can see here there seems to be an auth issue?

here is my config

        Exponea.shared.configure(
            Exponea.ProjectSettings(
                projectToken: "PROJTOKEN",
                authorization: .token("AUTHTOKEN")
            ),
            pushNotificationTracking: .enabled(
                appGroup: "APPGRP"
            )
        )
wassil commented 3 years ago

I think you have to configure your access token on Exponea backend. In the version you're migrating to we added a customer property apple_push_notification_authorized and your token is most probably not able to create it - that's why you're getting "not authorized to update specified customer properties"

Go to Project Settings/API and look at "API groups". Select the group that you're using in your app(most probably it's default). Then check the "Group permissions" below that. You should allow the token to either create new customer properties, or create the property apple_push_notification_authorized and allow the token to write into it.

jackjpark commented 3 years ago

I think you have to configure your access token on Exponea backend. In the version you're migrating to we added a customer property apple_push_notification_authorized and your token is most probably not able to create it - that's why you're getting "not authorized to update specified customer properties"

Go to Project Settings/API and look at "API groups". Select the group that you're using in your app(most probably it's default). Then check the "Group permissions" below that. You should allow the token to either create new customer properties, or create the property apple_push_notification_authorized and allow the token to write into it.

yep this seems to havbe fixed it, i had to allow the API group to create properties. THis should really be documented very clearly in a migration guide as I dont see where i could have found this info without creating an issue, thanks

edit: ok ive got it working now, it wasnt working on dev build tokens but works on staging

wassil commented 3 years ago

It shouldn't be changed in any way. I'd try to do a fresh install of the application. How are the tokens different? Btw. bad device token may also be result of incorrect bundle id or incorrect certificate(production vs. develoment)

jackjpark commented 3 years ago

It shouldn't be changed in any way. I'd try to do a fresh install of the application. How are the tokens different? Btw. bad device token may also be result of incorrect bundle id or incorrect certificate(production vs. develoment)

Ive sorted it now, seems tokens on the dev scheme just dont work, but on staging build they did so it seems to all be good now

wassil commented 3 years ago

They do work, buy you'd have to use a different(development) certificate for APNS

jackjpark commented 3 years ago

@wassil Im having an issue when a user taps a notification, itll execute twice, so im getting 2 webviews to open a URL for example. This is an issue I had with an older version of your SDK that was fixed but the issue is now back again, last time it was because a delegate method was called twice and needed an update to resolve. Any idea?

wassil commented 3 years ago

What do you mean by "it'll execute twice"? Which Exponea function is called twice? Do you use another SDKs to handle push notifications?