All Downloads are FREE. Search and download functionalities are using the official Maven repository.

main.com.enniovisco.tracking.commands.MetadataCollector.kt Maven / Gradle / Ivy

The newest version!
package com.enniovisco.tracking.commands

import io.github.oshai.kotlinlogging.*

class MetadataCollector(cmdExec: (String) -> Any) : BrowserCommand() {
    private val layoutVpWidth: String
    private val layoutVpHeight: String
    private val visualVpWidth: String
    private val visualVpHeight: String
    private val log = KotlinLogging.logger {}

    init {
        /*
           Document areas considered by the page, including unreachable ones.
           They are not tracked at all at the moment
        */
        // Layout Viewport: Scrollable area
        val layoutVp = "return document.documentElement"
        layoutVpWidth = cmdExec("${layoutVp}.scrollWidth").toString()
        layoutVpHeight = cmdExec("${layoutVp}.scrollHeight").toString()
        log.info { "Layout Viewport: ${layoutVpWidth}x${layoutVpHeight}" }

        // Visual Viewport: physical screen
        visualVpWidth = cmdExec("return window.innerWidth;").toString()
        visualVpHeight = cmdExec("return window.innerHeight;").toString()
        log.info { "Visual Viewport: ${visualVpWidth}x${visualVpHeight}" }
    }

    override fun dump(target: MutableMap) {
        target["lvp_width"] = layoutVpWidth
        target["lvp_height"] = layoutVpHeight
        target["vvp_width"] = visualVpWidth
        target["vvp_height"] = visualVpHeight
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy