Search code examples
htmlamp-html

Can we track html tags visibility in AMP?


Let's say I have div block somewhere middle on my web page. When it comes to the viewport, I want to track the visibility in AMP. As far as I know, AMP gives provision to track visibility for amp components. Is there any way that I can track the same for HTML tags like div, a, li?


Solution

  • In your googleanalytics configuration, set up the trigger with "on":"visible":

    "triggers": {
        "trigger name": {
            "on": "visible",
            "selector": "#divid",
            ....
         }
         ...
    

    See the section on "trigger" for more details: https://www.ampproject.org/docs/reference/components/amp-analytics#triggers