Giter Club home page Giter Club logo

Comments (9)

amkomatz-ggd avatar amkomatz-ggd commented on May 20, 2024 2

+1

from dd-sdk-ios.

maxep avatar maxep commented on May 20, 2024 1

SwiftUI Instrumentation APIs have been added in 1.9.0. Our documentation still need to be updated but here some snippets on how to use it:

  • View Instrumentation:
import SwiftUI
import Datadog

struct FooView: View {

    var body: some View {
        FooContent {
            ...
        }
        .trackRUMView(name: "Foo")
    }
}
  • Tap Action Instrumentation:
import SwiftUI
import Datadog

struct BarView: View {

    var body: some View {
        Button("BarButton") { {
            ...
        }
        .trackRUMTapAction(name: "Bar")
    }
}

It has been designed to work seamlessly with UIKit auto-instrumentation for hybrid UIKit+SwiftUI applications.
I will close this issue, but feel free to add any comment/feedback.

from dd-sdk-ios.

maxep avatar maxep commented on May 20, 2024 1

Hey @ferologics! Thanks for using it :)

We keep a stack of appeared view to consistently log start and stop view events, the last item of the stack is the visible one, any items below it have appeared but onDisappear has not been called. Therefore, they are considered not visible but can be revealed if the last item disappears.

So if we have the following sequence, characteristically of a modal navigation:

  1. View A onAppear
  2. View B onAppear
  3. View B onDisappear

The following events will be logged:

  1. Start View A
  2. Stop View A
  3. Start View B
  4. Stop View B
  5. Start View A

from dd-sdk-ios.

ncreated avatar ncreated commented on May 20, 2024

Hey @Alexander-techIOS ! Thanks for reaching out 🙂. We plan to support SwiftUI in the future, but I can't give any estimates. Please contact our support so we can track your interest in having SwiftUI compatibility for the iOS RUM SDK 💪.

from dd-sdk-ios.

saj11 avatar saj11 commented on May 20, 2024

Hi @ncreated!
I don't sure if it is the same issue but I am trying to integrate Datadog into a SwiftUI app. I understand that Datadog do not support SwiftUI, in terms of RUM, so it won't track the views or actions. But RUM also includes a mode in which it can tracks the request, but it seems to do not work also.

So I want to know if any feature inside Datadog will work on a SwiftUI app

from dd-sdk-ios.

ncreated avatar ncreated commented on May 20, 2024

Hello @saj11. Our manual instrumentation API offers a UI framework-agnostic variant which will work with SwiftUI as well. When using SwiftUI, you can leverage those two APIs to start and stop the RUM View:

Global.rum.startView(key:)
Global.rum.stopView(key:)

Network requests (auto)instrumentation will only work if there's a RUM View started, so please make sure that you call Global.rum.startView(key:) from your SwiftUI's view before the request is sent.

from dd-sdk-ios.

hs-echkayben avatar hs-echkayben commented on May 20, 2024

Hello @ncreated according to the manual instrumentation API you shared, Global.rum.startView(viewController: self) is the way to collect RUM resources. So what I don't understand how would that translate in the absence of a UIViewController in the case of swiftUI, the documentation is not clear when it comes to that. Thank you

from dd-sdk-ios.

ncreated avatar ncreated commented on May 20, 2024

Hello @hs-echkayben 👋. In case of view controller absence, you can use following APIs on RUMMonitor:

/// Notifies that the View starts being presented to the user.
/// - Parameters:
/// - key: a `String` value identifying this View. It must match the `key` passed later to `stopView(key:attributes:)`.
/// - name: the View name used for RUM Explorer. If not provided, the `key` name will be used.
/// - attributes: custom attributes to attach to the View.
public func startView(
key: String,
name: String? = nil,
attributes: [AttributeKey: AttributeValue] = [:]
) {}
/// Notifies that the View stops being presented to the user.
/// - Parameters:
/// - key: a `String` value identifying this View. It must match the `key` passed earlier to `startView(key:path:attributes:)`.
/// - attributes: custom attributes to attach to the View.
public func stopView(
key: String,
attributes: [AttributeKey: AttributeValue] = [:]
) {}

With that, you can start and stop the view by giving String key to match its ending with the beginning. In case of SwiftUI, I think this should work fine:

struct ContentView: View {
    private let viewKey = "content-view" // must be unique
    private let rumViewName = "ContentView"

    var body: some View {
        // ...
        .onAppear {
           Global.rum.startView(key: viewKey, name: rumViewName)
        }
        .onDisappear {
           Global.rum.stopView(key: viewKey)
        }
    }
}

from dd-sdk-ios.

ferologics avatar ferologics commented on May 20, 2024

@maxep thanks for the update, this is very helpful! I'm currently integrating I'm curious how does the trackRUMView(name:) method behave in case onDisappear() of the view is not called?

from dd-sdk-ios.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.