Total Visitors Currently online

Created on 6 November 2013, about 11 years ago
Updated 1 August 2023, over 1 year ago

Problem/Motivation

There's no "Who's online" module. I wish to show the total visitors/guests who are browsing the website, in the last 30 minutes, and last 24 hours.

Steps to reproduce

Proposed resolution

Use the unique visitor_id to display the number of unique visitors, for the past 30 minutes, and 24 hours. Display this in the Visitors' block

e.g. "There are 'n' visitors online"

Remaining tasks

πŸ“Œ Tracking cookies Fixed

User interface changes

Two additional metrics available in the visitors block.

API changes

Data model changes

✨ Feature request
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡²πŸ‡ΎMalaysia simone960

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

Comments & Activities

  • πŸ‡ΊπŸ‡ΈUnited States bluegeek9
  • πŸ‡«πŸ‡·France nicolas bouteille

    I am also interested in having this information on my website: how many users/visitors are currently online. I can't find a solution anywhere. Any idea?

  • πŸ‡ΊπŸ‡ΈUnited States bluegeek9

    You can create a view.

    Field: Unique Visitor - Count Distinct
    Aggregation: Yes
    Filter: Visitors_datetime >= -1 day

  • πŸ‡ΊπŸ‡ΈUnited States sah62 US

    You can create a view.

    Please say more. I just tried to create a view, and with aggregation disabled I see a unique ID for each visitor. When I enable aggregation and use the "Count Distinct" option for the Unique Visitor field, I get a value of "1" in the field and the records aren't aggregated. Maybe I'm doing something wrong, but I don't know what. I've also added the timestamp, IP address, and URL fields to the view. Here's my view config:

    uuid: 6f395cd4-37b8-47ba-a749-a8dc070506c8
    langcode: en
    status: true
    dependencies:
      module:
        - visitors
    id: online_visitors
    label: 'Online Visitors'
    module: views
    description: ''
    tag: ''
    base_table: visitors
    base_field: ''
    display:
      default:
        id: default
        display_title: Default
        display_plugin: default
        position: 0
        display_options:
          title: 'Online Visitors'
          fields:
            visitor_id:
              id: visitor_id
              table: visitors
              field: visitor_id
              relationship: none
              group_type: count_distinct
              admin_label: ''
              plugin_id: standard
              label: 'Unique visitor'
              exclude: false
              alter:
                alter_text: false
                text: ''
                make_link: false
                path: ''
                absolute: false
                external: false
                replace_spaces: false
                path_case: none
                trim_whitespace: false
                alt: ''
                rel: ''
                link_class: ''
                prefix: ''
                suffix: ''
                target: ''
                nl2br: false
                max_length: 0
                word_boundary: true
                ellipsis: true
                more_link: false
                more_link_text: ''
                more_link_path: ''
                strip_tags: false
                trim: false
                preserve_tags: ''
                html: false
              element_type: ''
              element_class: ''
              element_label_type: ''
              element_label_class: ''
              element_label_colon: true
              element_wrapper_type: ''
              element_wrapper_class: ''
              element_default_classes: true
              empty: ''
              hide_empty: false
              empty_zero: false
              hide_alter_empty: true
              set_precision: false
              precision: 0
              decimal: .
              separator: ','
              format_plural: 0
              format_plural_string: !!binary MQNAY291bnQ=
              prefix: ''
              suffix: ''
            visitors_date_time:
              id: visitors_date_time
              table: visitors
              field: visitors_date_time
              relationship: none
              group_type: group
              admin_label: ''
              plugin_id: date
              label: 'Visitors Date Time'
              exclude: false
              alter:
                alter_text: false
                text: ''
                make_link: false
                path: ''
                absolute: false
                external: false
                replace_spaces: false
                path_case: none
                trim_whitespace: false
                alt: ''
                rel: ''
                link_class: ''
                prefix: ''
                suffix: ''
                target: ''
                nl2br: false
                max_length: 0
                word_boundary: true
                ellipsis: true
                more_link: false
                more_link_text: ''
                more_link_path: ''
                strip_tags: false
                trim: false
                preserve_tags: ''
                html: false
              element_type: ''
              element_class: ''
              element_label_type: ''
              element_label_class: ''
              element_label_colon: true
              element_wrapper_type: ''
              element_wrapper_class: ''
              element_default_classes: true
              empty: ''
              hide_empty: false
              empty_zero: false
              hide_alter_empty: true
              date_format: fallback
              custom_date_format: ''
              timezone: ''
            visitors_ip:
              id: visitors_ip
              table: visitors
              field: visitors_ip
              relationship: none
              group_type: group
              admin_label: ''
              plugin_id: standard
              label: 'Visitors IP'
              exclude: false
              alter:
                alter_text: false
                text: ''
                make_link: false
                path: ''
                absolute: false
                external: false
                replace_spaces: false
                path_case: none
                trim_whitespace: false
                alt: ''
                rel: ''
                link_class: ''
                prefix: ''
                suffix: ''
                target: ''
                nl2br: false
                max_length: 0
                word_boundary: true
                ellipsis: true
                more_link: false
                more_link_text: ''
                more_link_path: ''
                strip_tags: false
                trim: false
                preserve_tags: ''
                html: false
              element_type: ''
              element_class: ''
              element_label_type: ''
              element_label_class: ''
              element_label_colon: true
              element_wrapper_type: ''
              element_wrapper_class: ''
              element_default_classes: true
              empty: ''
              hide_empty: false
              empty_zero: false
              hide_alter_empty: true
              set_precision: false
              precision: 0
              decimal: .
              separator: ','
              format_plural: false
              format_plural_string: !!binary MQNAY291bnQ=
              prefix: ''
              suffix: ''
            visitors_url:
              id: visitors_url
              table: visitors
              field: visitors_url
              relationship: none
              group_type: group
              admin_label: ''
              plugin_id: standard
              label: 'Visitors URL'
              exclude: false
              alter:
                alter_text: false
                text: ''
                make_link: false
                path: ''
                absolute: false
                external: false
                replace_spaces: false
                path_case: none
                trim_whitespace: false
                alt: ''
                rel: ''
                link_class: ''
                prefix: ''
                suffix: ''
                target: ''
                nl2br: false
                max_length: 0
                word_boundary: true
                ellipsis: true
                more_link: false
                more_link_text: ''
                more_link_path: ''
                strip_tags: false
                trim: false
                preserve_tags: ''
                html: false
              element_type: ''
              element_class: ''
              element_label_type: ''
              element_label_class: ''
              element_label_colon: true
              element_wrapper_type: ''
              element_wrapper_class: ''
              element_default_classes: true
              empty: ''
              hide_empty: false
              empty_zero: false
              hide_alter_empty: true
          pager:
            type: full
            options:
              offset: 0
              pagination_heading_level: h4
              items_per_page: 20
              total_pages: null
              id: 0
              tags:
                next: 'Next β€Ί'
                previous: 'β€Ή Previous'
                first: 'Β« First'
                last: 'Last Β»'
              expose:
                items_per_page: false
                items_per_page_label: 'Items per page'
                items_per_page_options: '5, 10, 25, 50'
                items_per_page_options_all: false
                items_per_page_options_all_label: '- All -'
                offset: false
                offset_label: Offset
              quantity: 9
          exposed_form:
            type: basic
            options:
              submit_button: Apply
              reset_button: false
              reset_button_label: Reset
              exposed_sorts_label: 'Sort by'
              expose_sort_order: true
              sort_asc_label: Asc
              sort_desc_label: Desc
          access:
            type: none
            options: {  }
          cache:
            type: tag
            options: {  }
          empty: {  }
          sorts: {  }
          arguments: {  }
          filters:
            visitors_date_time:
              id: visitors_date_time
              table: visitors
              field: visitors_date_time
              relationship: none
              group_type: group
              admin_label: ''
              plugin_id: visitors_date
              operator: '>='
              value:
                min: ''
                max: ''
                value: '-1 hour'
                type: offset
              group: 1
              exposed: false
              expose:
                operator_id: ''
                label: ''
                description: ''
                use_operator: false
                operator: ''
                operator_limit_selection: false
                operator_list: {  }
                identifier: ''
                required: false
                remember: false
                multiple: false
                remember_roles:
                  authenticated: authenticated
                min_placeholder: ''
                max_placeholder: ''
                placeholder: ''
              is_grouped: false
              group_info:
                label: ''
                description: ''
                identifier: ''
                optional: true
                widget: select
                multiple: false
                remember: false
                default_group: All
                default_group_multiple: {  }
                group_items: {  }
          style:
            type: table
            options:
              grouping: {  }
              row_class: ''
              default_row_class: true
              columns:
                visitors_date_time: visitors_date_time
                visitors_ip: visitors_ip
                visitors_url: visitors_url
              default: visitors_date_time
              info:
                visitors_date_time:
                  sortable: true
                  default_sort_order: desc
                  align: ''
                  separator: ''
                  empty_column: false
                  responsive: ''
                visitors_ip:
                  sortable: false
                  default_sort_order: desc
                  align: ''
                  separator: ''
                  empty_column: false
                  responsive: ''
                visitors_url:
                  sortable: false
                  default_sort_order: asc
                  align: ''
                  separator: ''
                  empty_column: false
                  responsive: ''
              override: true
              sticky: false
              summary: ''
              empty_table: false
              caption: ''
              description: ''
          row:
            type: fields
          query:
            type: views_query
            options:
              query_comment: ''
              disable_sql_rewrite: false
              distinct: false
              replica: false
              query_tags: {  }
          relationships: {  }
          group_by: true
          header: {  }
          footer: {  }
          display_extenders: {  }
        cache_metadata:
          max-age: -1
          contexts:
            - 'languages:language_interface'
            - url.query_args
          tags: {  }
      block_1:
        id: block_1
        display_title: Block
        display_plugin: block
        position: 1
        display_options:
          display_extenders: {  }
          block_description: 'Online Visitors'
        cache_metadata:
          max-age: -1
          contexts:
            - 'languages:language_interface'
            - url.query_args
          tags: {  }
    
  • πŸ‡ΊπŸ‡ΈUnited States bluegeek9
    uuid: 6f395cd4-37b8-47ba-a749-a8dc070506c8
    langcode: en
    status: true
    dependencies:
      module:
        - visitors
    id: online_visitors
    label: 'Online Visitors'
    module: views
    description: ''
    tag: ''
    base_table: visitors
    base_field: ''
    display:
      default:
        id: default
        display_title: Default
        display_plugin: default
        position: 0
        display_options:
          title: 'Online Visitors'
          fields:
            visitor_id:
              id: visitor_id
              table: visitors
              field: visitor_id
              relationship: none
              group_type: count_distinct
              admin_label: ''
              plugin_id: standard
              label: 'Visitor Online'
              exclude: false
              alter:
                alter_text: false
                text: ''
                make_link: false
                path: ''
                absolute: false
                external: false
                replace_spaces: false
                path_case: none
                trim_whitespace: false
                alt: ''
                rel: ''
                link_class: ''
                prefix: ''
                suffix: ''
                target: ''
                nl2br: false
                max_length: 0
                word_boundary: true
                ellipsis: true
                more_link: false
                more_link_text: ''
                more_link_path: ''
                strip_tags: false
                trim: false
                preserve_tags: ''
                html: false
              element_type: ''
              element_class: ''
              element_label_type: ''
              element_label_class: ''
              element_label_colon: true
              element_wrapper_type: ''
              element_wrapper_class: ''
              element_default_classes: true
              empty: ''
              hide_empty: false
              empty_zero: false
              hide_alter_empty: true
              set_precision: false
              precision: 0
              decimal: .
              separator: ','
              format_plural: 0
              format_plural_string: !!binary MQNAY291bnQ=
              prefix: ''
              suffix: ''
          pager:
            type: none
            options:
              offset: 0
          exposed_form:
            type: basic
            options:
              submit_button: Apply
              reset_button: false
              reset_button_label: Reset
              exposed_sorts_label: 'Sort by'
              expose_sort_order: true
              sort_asc_label: Asc
              sort_desc_label: Desc
          access:
            type: none
            options: {  }
          cache:
            type: tag
            options: {  }
          empty: {  }
          sorts: {  }
          arguments: {  }
          filters:
            visitors_date_time:
              id: visitors_date_time
              table: visitors
              field: visitors_date_time
              relationship: none
              group_type: group
              admin_label: ''
              plugin_id: visitors_date
              operator: '>='
              value:
                min: ''
                max: ''
                value: '-1 hour'
                type: offset
              group: 1
              exposed: false
              expose:
                operator_id: ''
                label: ''
                description: ''
                use_operator: false
                operator: ''
                operator_limit_selection: false
                operator_list: {  }
                identifier: ''
                required: false
                remember: false
                multiple: false
                remember_roles:
                  authenticated: authenticated
                min_placeholder: ''
                max_placeholder: ''
                placeholder: ''
              is_grouped: false
              group_info:
                label: ''
                description: ''
                identifier: ''
                optional: true
                widget: select
                multiple: false
                remember: false
                default_group: All
                default_group_multiple: {  }
                group_items: {  }
          style:
            type: html_list
            options:
              grouping: {  }
              row_class: ''
              default_row_class: true
              type: ul
              wrapper_class: item-list
              class: ''
          row:
            type: fields
          query:
            type: views_query
            options:
              query_comment: ''
              disable_sql_rewrite: false
              distinct: false
              replica: false
              query_tags: {  }
          relationships: {  }
          group_by: true
          header: {  }
          footer: {  }
          display_extenders: {  }
        cache_metadata:
          max-age: -1
          contexts:
            - 'languages:language_interface'
          tags: {  }
      block_1:
        id: block_1
        display_title: Block
        display_plugin: block
        position: 1
        display_options:
          display_extenders: {  }
          block_description: 'Online Visitors'
        cache_metadata:
          max-age: -1
          contexts:
            - 'languages:language_interface'
          tags: {  }
    
    
  • πŸ‡ΊπŸ‡ΈUnited States sah62 US

    The config above produces a view that says I have n unique visitors, but it doesn't specifically identify them. That addresses the request as described above. My mistake, sorry.

    I was trying to produce a view that lists those unique visitors in a table, aggregating them by IP address or unique visitor ID, and showing me that IP address along with the timestamp and URL of their most recent visit. My view comes close to that, but it fails to aggregate the visits. Back to the drawing board...

  • πŸ‡ΊπŸ‡ΈUnited States bluegeek9

    Sah62,

    You will need to wait for 3.0.0. We will add the concept of a visit; a 30-minute period of inactivity ends a visit.

    The visit table will store the visitor's first and last page views.

    ✨ track Session - 30 minutes Active
    🌱 Roadmap Postponed

Production build 0.71.5 2024