8SELECT - Integration Documentation
8SELECTService Status
  • 8.HX PLATFORM
  • Shop Integration
    • 8.SDK Web (JavaScript SDK)
    • Widgets
      • βž•Add more elements, like custom headline
      • πŸ‘»Hide recommendation area in case there is no content
      • πŸ”ŽAdding widgets after 8.SDK was loaded
      • πŸ—ΊοΈInternationalization
    • Shopping Cart
    • Checkout Tracking
    • Product Export
    • A/B Testing
    • Single Page Application
    • Tag Manager
    • Data Privacy / Cookies / GDPR
  • Widgets
    • 8.SIMILAR
    • 8.SET
    • 8.SET Custom
    • Touchpoints
      • Product Page
      • Cart Layer
      • Cart
      • Content Page
  • Product Export
    • Data Transfer
    • File Format
    • Base Data
      • Details and examples
    • Fashion Content Pool
      • Details and examples
    • Image Bot
  • Sandbox
    • Demo-Integration
    • Demo-Mode
  • API
    • Changelog
      • 2.0.0
      • 1.0.1
    • General
      • Introduction
      • Authentication
      • Pagination
      • Exceptions
      • GraphQL Schema
    • Examples
      • 8.SIMILAR
      • 8.SET
      • 8.SET Custom
      • Product Page - All Content
  • API Tracking
    • Changelog
    • General
      • Introduction
      • Authentication
      • Context
      • User Identification
      • Event Validation
    • Events
      • view
        • How to evaluate if view event can be sent
        • User views 8.SET content
      • interact
        • User clicks on a product within 8.SET content
        • User adds a product to their card from within 8.SET content
        • Example what is not a product interaction
      • order
Powered by GitBook
On this page
  • Example cases
  • 50% of the content is visible in the viewport
  • The content is visible on 50% of the viewport
  • Code Snippet

Was this helpful?

  1. API Tracking
  2. Events
  3. view

How to evaluate if view event can be sent

PreviousviewNextUser views 8.SET content

Last updated 10 months ago

Was this helpful?

Our KPIs require that a view event is only send if the according content is inside the user's viewport.

Example cases

There are two cases when content is eligible to trigger such an event

50% of the content is visible in the viewport

The content is visible on 50% of the viewport

Code Snippet

const getDimensions = node => {
  const nodeOffsetY = node.getBoundingClientRect().top + window.scrollY
  const nodeHeight = node.getBoundingClientRect().height
  const viewOffsetY = window.scrollY
  const viewHeight = window.innerHeight
  return { nodeOffsetY, nodeHeight, viewOffsetY, viewHeight }
}

const isHalfViewFilledByNode = node => {
  const { nodeOffsetY, nodeHeight, viewOffsetY, viewHeight } = getDimensions(node)
  const topNodeIsFillingBottomHalfView = viewOffsetY + viewHeight / 2 >= nodeOffsetY
  const bottomNodeIsFillingTopHalfView = viewOffsetY + viewHeight / 2 <= nodeOffsetY + nodeHeight

  return topNodeIsFillingBottomHalfView && bottomNodeIsFillingTopHalfView
}

const isHalfNodeVisible = node => {
  const { nodeOffsetY, nodeHeight, viewOffsetY, viewHeight } = getDimensions(node)
  const viewBottomIsBelowTopHalfNode = viewOffsetY + viewHeight >= nodeOffsetY + nodeHeight / 2
  const viewTopIsAboveBottomHalfNode = viewOffsetY <= nodeOffsetY + nodeHeight / 2

  return viewBottomIsBelowTopHalfNode && viewTopIsAboveBottomHalfNode
}

export default node => {
  const isNodeHidden = node.offsetParent === null // if one of the parents is display none, this will be null
  const isNodeFixed = node.style.position === 'fixed' // position fixed has no offsetParent

  if (isNodeHidden && !isNodeFixed) {
    return false
  }

  return isHalfViewFilledByNode(node) || isHalfNodeVisible(node)
}
event is triggered when 50% of the content is visible
event is triggered when 50% of the viewport is filled with the content