View Counter:field: Any Entity Type

Created on 24 July 2023, over 1 year ago

Problem/Motivation

Modern Drupal sites have more entities than just Nodes. Most entities do not have a links region.

Steps to reproduce

Proposed resolution

Add a pseudo field to all entities who's views are being counted.

Remaining tasks

User interface changes

Settings Form will contain options for other Entity Types.

API changes

Data model changes

📌 Task
Status

Active

Version

2.0

Component

Code

Created by

🇺🇸United States bluegeek9

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @bluegeek9
  • 🇹🇭Thailand AlfTheCat

    This would be really great to have, I have a site that would really benefit from the ability to show users the views of all their entities (products and taxonomy terms). Right now, if reporting only node views, the stats would be greatly under reported.

    If we could include a pseudo field to a view mode or views display it would be fantastic.

  • 🇩🇪Germany kreatIL

    I maintain a Drupal site with around 30,000 media entities, which constitute approximately 95% of our content. The Visitors module would be incredibly useful for us to track and analyze user interactions with this content.

    I appreciate the discussion here about extending entity types, and I want to echo the value of this enhancement. Supporting media entities would allow us to gain detailed insights into user engagement across all content types, making Visitors a powerful tool for a wider range of Drupal sites.

  • 🇺🇸United States bluegeek9

    Hi,

    The code already supports recording additional entity types. The issue I ran into was how to display the view count. Nodes have a links region. Links is where the Statistics project displays the view count. Other entity types do not necessarily have links. I try a pseudo field but it did not look good.

    How would you want to show the view count for a Media entity?

    You might be able to accomplish some of what you need with the views plugins introduced in 8.x-2.20.

  • 🇹🇭Thailand AlfTheCat

    If we could leverage views it would already be great because the https://www.drupal.org/project/viewfield module could then allow it to be added to any view mode of any entity.

  • 🇺🇸United States bluegeek9

    @alfthecat,

    The code supports views.

    Suppose you edit visitors.config and add the entity types to counter.entity_types, it will count the visits and you will be able to access the count in views. There is not an option in the settings to add the entity types. You well need to do it manually.

  • 🇹🇭Thailand AlfTheCat

    Hi @bluegeek, thanks for clarifying that.

    One additional thought I had based on this conversation, is that in some cases (like my marketplace), it would be very valuable if we could track impressions by viewmode or a view.

    If we could then build reporting views and display statistics by view mode, it would open up the possibility of offering the boosting of posts, user profiles, and other forms of content promotion to the site's users. If the site sells ad space, this would be vital.

    Just a thought, not sure if a psuedo field would be the way to go but I imagine adding it to a view mode to initiate tracking might be handy and intuitive for site builers.

  • 🇺🇸United States bluegeek9

    @alfthecat,

    Does the view mode correspond to a URL?

    Display views, or Form Views, or both?

    Are the ads in Blocks?

  • 🇹🇭Thailand AlfTheCat

    Hi @bluegeek,

    The example I'm thinking of, and the kind of site I'm referring to, is like one of those food delivery platforms (it can apply to any kind of directory and marketplace). Let's say each restaurant has a page and they add their menu items as commerce products. Both the restaurant nodes and the commerce products leverage view modes. The restaurant nodes would have a viewmode for "full view" and "ad". The products would have a "full view" and "catalog" viewmode, the latter styled for display in a typical catalog grid.

    To restaurant owners, it would be useful to see how often their dishes were shown to users on the site, which would be the "catalog" view mode. Also, restaurant owners might want to boost their page at a fee, so then it would be necessary to report how often their restaurant node's "ad" viewmode was served to users of the site.

    Adding a psuedo-field to the entity, maybe one for each viewmode, would be an easy way to add a segmented "counter" to entities and views for site builders. Maybe there's a better approach, but I think this kind of reporting would be very valuable for this kind of platform.

    I currently display a footnote under the user's visitor count stating it doesn't include product views or views in recommender views distributed across the site and am not able to provide a "boosting" feature because there would be no way of reporting the results.

  • 🇺🇸United States bluegeek9

    alfthecat,

    Tracking impressions might be something that can be done with 'Visitors Actions'.

    Visitor Actions Active

  • 🇹🇭Thailand AlfTheCat

    Thanks! That will be very interesting!

  • 🇩🇪Germany drupalbubb

    I have some views pages configured to sort and display my nodes. Now I would like to find the page hits counter maybe in the footer line section of my views.

  • 🇺🇸United States bluegeek9

    @drupalbubb,

    You need to add a relationship to your view, Visitor Counters. Three fields can now be added: Most recent visit, Total views, and Views today.

  • Merge request !214Resolve #3376634 "View counterfield any" → (Merged) created by bluegeek9
  • Pipeline finished with Skipped
    about 2 months ago
    #426909
  • Pipeline finished with Skipped
    about 2 months ago
    #426912
  • 🇺🇸United States bluegeek9

    I am seeking feedback on this feature before publishing a new release.

  • 🇩🇪Germany drupalbubb

    I installed 8.x-2.x-dev, but it does not help me. There is no entity type "views" checkbox.
    I would like to display all visits of my views page, not per node via a field as suggested, just simple page hits. There should be an easy way to add it to the footer line, displayed like the node counter field for nodes.
    More complex is my second layer view, showing all nodes inside a category, configured via a context filter. Configured as one view, listing the related nodes. This should display the sum of all page hits related to the context filter, not the sum of the view hits.

  • 🇺🇸United States bluegeek9

    @drupalbubb,

    Thanks for testing the new feature.

    We added support for all content entity types.

    Config entity types, like views, and other non-content entity types are handled under Impression tracking Active

  • 🇺🇸United States bluegeek9

    bluegeek9 changed the visibility of the branch 8.x-2.x to hidden.

  • 🇺🇸United States bluegeek9

    The popular block needs to be updated to control which entity types are shown.

    src/Plugin/Block/VisitorsPopularBlock.php.html

  • Merge request !219Resolve #3376634 "Popular block" → (Merged) created by bluegeek9
  • Pipeline finished with Skipped
    about 1 month ago
    #437316
    • bluegeek9 committed fce6a668 on 8.x-2.x
      Issue #3376634 by bluegeek9: View Counter:field: Any Content Entity Type
      
  • Pipeline finished with Skipped
    about 1 month ago
    #437321
    • bluegeek9 committed 2697ccbe on 3.0.x
      Issue #3376634 by bluegeek9: View Counter:field: Any Content Entity Type
      
  • 🇺🇸United States bluegeek9

    The visitors popular block now works with any configured content entity type.

  • 🇺🇸United States bluegeek9

    The block's access method should be updated to check if counting and the configured entity type are enabled.

    The Blocks Cache Tag should include 'config:visitors.config'

  • 🇺🇸United States bluegeek9

    The tokens might also need updating to support additional entities.

  • Pipeline finished with Failed
    23 days ago
    #450732
  • Pipeline finished with Failed
    23 days ago
    #450779
  • Merge request !237Resolve #3376634 "3 block access" → (Merged) created by bluegeek9
  • Pipeline finished with Skipped
    20 days ago
    #453639
    • bluegeek9 committed cb4d92c2 on 3.0.x
      Issue #3376634 by bluegeek9: View Counter:field: Any Content Entity Type
      
  • Merge request !238Resolve #3376634 "Block access" → (Merged) created by bluegeek9
  • Pipeline finished with Skipped
    18 days ago
    #454960
    • bluegeek9 committed f513c78e on 8.x-2.x
      Issue #3376634 by bluegeek9: View Counter:field: Any Content Entity Type
      
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024