Skip to content

CLI: 'analytics ga path_sequence' floods 'Array to string conversion' (AnalyticsCommand.php:249) in table format — flatten_row can't handle nested next_hosts arrays #2633

Description

@chubes4

Symptom

wp datamachine analytics ga path_sequence --start-date=... --end-date=... emits a flood of:

Warning: Array to string conversion in .../data-machine/inc/Cli/Commands/AnalyticsCommand.php on line 249

and prints no usable table. --format=json works fine and returns valid, complete data.

Root cause

path_sequence (the GA4 v1alpha funnel action from dmb#35) returns rows whose next_hosts value is an array of objects ([{next_host, users}, ...]), i.e. a nested array-of-arrays per host.

flatten_row() (AnalyticsCommand.php ~244-255) handles one level of array via implode(', ', array_map('strval', $value)):

foreach ( $row as $key => $value ) {
    if ( is_array( $value ) ) {
        $flat[ $key ] = implode( ', ', array_map( 'strval', $value ) );  // <-- L249: array_map strval on an array-of-arrays
    } else {
        $flat[ $key ] = $value;
    }
}

When $value is next_hosts (an array whose elements are themselves arrays), strval() is called on each inner array → "Array to string conversion", once per inner element, hence the flood.

Impact

path_sequence is the best instrument for cross-site/network-density measurement (user-scoped activeUsers, bot-resistant — unlike the session-scoped UTM bridge channel which is ~98% bot-inflated). It's currently only usable via --format=json; the default table view is broken, which makes it look broken to anyone who runs it the normal way.

Fix options

  • In flatten_row(), when an array value contains nested arrays/objects, JSON-encode it (or summarize, e.g. host(users); host(users)) instead of implode+strval. A targeted path_sequence formatter that renders next_hosts as next_host:users pairs would be the nicest table output.
  • Or detect non-scalar inner elements and wp_json_encode() them as the cell value.

Repro

wp datamachine analytics ga path_sequence --start-date=2026-05-18 --end-date=2026-06-15
# -> flood of Array to string conversion at AnalyticsCommand.php:249
wp datamachine analytics ga path_sequence --start-date=2026-05-18 --end-date=2026-06-15 --format=json
# -> works, returns hostName/entry_users/onward_users/next_hosts[]

Env

extrachill.com VPS. data-machine CLI. path_sequence action (data-machine-business GoogleAnalyticsAbilities, dmb#35).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions