RegisterDevice
The RegisterDevice method registers a user's device for push notifications.
Usage
err := client.RegisterDevice(ctx, payload)
Parameters
| Name | Type | Description |
|---|---|---|
ctx | context.Context | Context for the request. |
payload | cdp.DevicePayload | Struct containing device details. |
DevicePayload Struct
| Field | Type | Required | Description |
|---|---|---|---|
UserID | string | ✅ | User identifier. |
DeviceID | string | ✅ | Unique device identifier (stable across token refreshes). |
Platform | string | ✅ | Platform: "android", "ios", or "web". |
DeviceToken | string | ✅ | FCM/APNS push notification token. |
Name | string | Device name. | |
OSVersion | string | Operating system version. | |
Model | string | Device model. | |
AppVersion | string | Application version. | |
LastActiveAt | string | Last active timestamp. | |
APNToken | string | Apple Push Notification token (iOS). | |
Attributes | map[string]interface{} | Additional device attributes. |
Device ID Best Practices
DeviceID Must Be Stable
The DeviceID should be a stable, unique identifier for the physical device (e.g., a UUID generated on first app install). The DeviceToken (FCM/APNS) can change when users reinstall the app or refresh tokens.
Using DeviceID ensures the same device isn't registered multiple times in Customer.io.
Example
payload := cdp.DevicePayload{
UserID: "user_123",
DeviceID: "device-uuid-abc123", // Stable device identifier
Platform: "android",
DeviceToken: "fcm-token-xyz789", // Push token (can change)
Model: "Pixel 6",
OSVersion: "13",
AppVersion: "1.2.0",
}
if err := client.RegisterDevice(context.Background(), payload); err != nil {
log.Println("Error registering device:", err)
}