Core Features
Analytics
The Hydra SDK enables comprehensive tracking of user actions and attributes, allowing you to understand user behavior and segment your audience effectively.
All analytics methods are called on the Hydra instance obtained during initialization (e.g., hydraSDK).
Identifying Users (Sign Up / Sign In / Sign Out)
It’s crucial to identify users when they log in or register to associate events correctly with their profiles.
User Sign Up:
Call reportUserSignUP
when a new user registers in your app.
- Prepare user details
let userDetails \= UserDetails(
customerId
: "new\_user\_123", // Required: Unique user identifier
firstName
: "New", // Optional
lastName
: "User", // Optional
email
: "[[email protected]](mailto:[email protected])", // Optional
phone
: "+15551234567") // Optional
- Add custom attributes (optional)
let customAttributes : [String:Any] =
["registrationMethod":"Email",
"referralSource":"CampaignXYZ"] hydraSDK
?.reportUserSignUP(data
: userDetails, customData
: customAttributes)
// IMPORTANT: Also update the SDK's customerId
// immediately after sign-up/sign-in
hydraSDK
?.update(customerID
: "new_user_123")
User Sign In:
Call reportUserSignIn
when an existing user logs in.
- Prepare user details (provide known details)
let userDetails = UserDetails(customerId
: "existing_user_456", // Required
firstName
: "Existing", lastName
: "User", email
: "[email protected]", phone
: "+15559876543")
- Custom attributes relevant to sign-in (optional)
// Optional: Custom attributes relevant to sign-in
let customAttributes : [String:Any] = ["loginMethod":"Password"]
hydraSDK
?.reportUserSignIn(data
: userDetails, customData
: customAttributes)
Note
Update the SDK's customerId immediately after sign-up/sign-in using:
hydraSDK?.update(customerID: "existing\_user\_456")
User Sign Out:
Call reportUserSignOut when a user logs out. This clears the associated user data within the SDK’s context for subsequent events (until the next sign-in/sign-up).
Custom attributes relevant to sign-out (optional)
let customAttributes: [String: Any] = [
"reason": "UserInitiated"
]
hydraSDK?.reportUserSignOut(customData: customAttributes)
Note:
- Update customerID to a guest ID or clear it if necessary using any of the following
hydraSDK?.update(customerID: "GUEST\_ID")
potentially hydraSDK?.update(customerID: "")
- The
UserDetails
struct (conforming toUserDetailsGenerator
) is used to pass user information. Ensure you provide at least thecustomerId
.
Updating User Profile Attributes
Use reportUserProfileUpdate
to send updates to a user’s profile information or custom attributes at any time after they are identified.
- Prepare updated user details (only include fields that changed or need setting)
let updatedUserDetails \=
UserDetails(customerId
: "existing\_user\_456", // Required
firstName
: "ExistingUpdated",
// lastName, email, phone can be omitted if not changing
...)
- Include any custom attributes to update or add
let customAttributes : \[String:Any\] \= \
["preferredLanguage":"fr",
"loyaltyTier":"Gold",
"lastPurchaseDate":Date() // Ensure dates are properly formatted if needed
\]
- Update user subscriptions for example, newsletter opt-in/out (optional)
struct MySubscription : Codable{
let channel : String let type : String // e.g., "OPTIN" / "OPTOUT"
} let subscriptions : [MySubscription] =
[
MySubscription(channel
: "EMAIL_NEWSLETTER", type
: "OPTIN"),
MySubscription(channel
: "SMS_PROMOTIONS", type
: "OPTOUT")
]
hydraSDK
?.reportUserProfileUpdate(
data
: updatedUserDetails, customData
: customAttributes,
subscriptions
: subscriptions) // Pass subscriptions if applicable
Notes
- The structure/format of subscription objects depends on your specific implementation.
- Ensure the objects conform to Codable/Encodable or are valid JSON types.
Tracking Custom Behavioral Events
Use reportBehavioralEvent
to track any custom action a user performs within your app. This is essential for understanding engagement and triggering campaigns.
- Example: Tracking product view
let eventName \= "ProductViewed" let attributes : \[String:Any\] \= \ ["productID":"SKU12345", "productName":"Hydra T-Shirt", "category":"Apparel", "price":29.99, "currency":"USD" \] hydraSDK ?.reportBehavioralEvent(name : eventName, customAttributes : attributes)
- Example: Tracking checkout step
let checkoutEvent \= "CheckoutStepCompleted" let checkoutAttrs : \ [String:Any\] \= \["stepNumber":2, "stepName":"ShippingAddress", "cartValue":150.75 \] hydraSDK ?.reportBehavioralEvent(name : checkoutEvent, customAttributes : checkoutAttrs)
- Example: Tracking a simple button click
hydraSDK?.reportBehavioralEvent(name: "ShareButtonClicked", customAttributes: \[:\]) //No extra attributes needed
Updated 1 day ago