Skip to main content

RegisterDevice

The RegisterDevice method registers a user's device for push notifications.

Usage​

err := client.RegisterDevice(ctx, payload)

Parameters​

NameTypeDescription
ctxcontext.ContextContext for the request.
payloadcdp.DevicePayloadStruct containing device details.

DevicePayload Struct​

FieldTypeRequiredDescription
UserIDstring✅User identifier.
DeviceIDstring✅Unique device identifier (stable across token refreshes).
Platformstring✅Platform: "android", "ios", or "web".
DeviceTokenstring✅FCM/APNS push notification token.
NamestringDevice name.
OSVersionstringOperating system version.
ModelstringDevice model.
AppVersionstringApplication version.
LastActiveAtstringLast active timestamp.
APNTokenstringApple Push Notification token (iOS).
Attributesmap[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)
}