Automatic Tracking
    • 1 Minute to read
    • Dark
      Light

    Automatic Tracking

    • Dark
      Light

    Article summary

    Automatic tracking is enabled by default in the SDK, automatically tracking every activity and fragment. It generates a page name (also known as Content ID) using the class name of the activity or fragment. You can customize or disable automatic tracking for specific screens by modifying the Global Configuration.

    Customizing Automatic Tracking

    Disable Automatic Tracking for Specific Screens:
    Use the @StopTrack annotation to prevent specific screens or activities from being automatically tracked.

    Method Overview

    Annotation

    Description

    @StopTrack

    Disables automatic tracking for specific screens or activities.

    TrackPageDetail(
    	val contextName: String = "", 
    	val trackingParams: Array<TrackParams> = []
    )

    Adds custom parameters to a screen when automatic tracking is enabled. If contextName is empty, the activity’s name is used. Otherwise, the provided contextName is taken as the page name.

    Important Notes

    • Kotlin Support: The @TrackPageDetail function works natively with Kotlin, allowing you to add parameters to specific screens. For Java-based apps, it only supports static values.

    • Avoid Double Tracking: When using automatic tracking, avoid using trackCustomPage() from manual tracking to prevent tracking the same screen multiple times, which can distort your analytics.

    • Track Events and Page Parameters with Auto-Tracking: You can still track events and page parameters even if automatic tracking is enabled. Refer to the documentation for more details.

    Examples

    Adding Custom Page Details

    Use @TrackPageDetail to add parameters for a specific page:

    @TrackPageDetail (
         contextName = "Main Page" ,
         trackingParams = [TrackParams(Param.INTERNAL_SEARCH, paramVal = "search term" )]
    )
    class MainActivity : AppCompatActivity() {
    }
    @TrackPageDetail (
         contextName = "Main Page" ,
         trackingParams = { @TrackParams (paramKey = "is" , paramVal = "new search" )}
     
    )
    public class MainActivity extends AppCompatActivity() {
    }

    In Java, you must include the actual key that is to be sent to Intelligence (e.g. "cp1" if you want to send the value of custom page parameter 1).

    Disabling Auto-Tracking for a Specific Screen

    Use @StopTrack to stop tracking for specific screens:

    @StopTrack
    class MainActivity : AppCompatActivity() {
    }
    @StopTrack
    public class MainActivity extends AppCompatActivity() {
    }


    Was this article helpful?