Install Search Statistics

Edit on GitHub

This document describes how to install the Search Statistics feature.

Prerequisites

Install the required features:

NAME VERSION
Spryker Core ^3.46.0
spryker-shop/shop-ui 1.107.0
spryker-shop/traceable-event-widget 1.2.0

1) Install the required modules using Composer

composer require spryker-eco/google-analytics:"^1.0.0" --update-with-dependencies

2) Enable the protobuf PHP extension

Search Statistics requires the protobuf PHP extension. The spryker/php Docker image includes the extension but does not load it by default, so you must enable it in the deploy file.

The Docker SDK has no separate switch for protobuf. Use one of the following options in every deploy file you use, such as local, staging, and production.

Option 1: Enable the otel extension

The otel extension loads opentelemetry, grpc, and protobuf together. To enable it, add otel to image: php: enabled-extensions:

image:
    tag: spryker/php:8.3
    php:
        enabled-extensions:
            - otel

Option 2: Load only the protobuf extension

If your project uses New Relic or otherwise does not need opentelemetry and grpc, load only protobuf through the php.ini configuration of the deploy file:

image:
    tag: spryker/php:8.3
    php:
        ini:
            extension: protobuf

After you choose an option, rebuild the images and restart the application:

docker/sdk boot your_deploy_file.yml && docker/sdk up
Verification

Make sure the protobuf extension is loaded:

docker/sdk cli php --ri protobuf

The command must return the extension information, including its version, instead of Extension 'protobuf' not present.

Verification

Make sure the following modules have been installed:

MODULE EXPECTED DIRECTORY
GoogleAnalytics vendor/spryker-eco/google-analytics

3) Generate transfer objects

console transfer:generate
Verification

Verify that the following transfer objects have been generated:

TRANSFER TYPE EVENT PATH
GoogleAnalyticsEvent class created src/Generated/Shared/Transfer/GoogleAnalyticsEventTransfer
GoogleAnalyticsEventConditions class created src/Generated/Shared/Transfer/GoogleAnalyticsEventConditionsTransfer
GoogleAnalyticsEventCriteria class created src/Generated/Shared/Transfer/GoogleAnalyticsEventCriteriaTransfer
GoogleAnalyticsEventCollection class created src/Generated/Shared/Transfer/GoogleAnalyticsEventCollectionTransfer

4) Generate translations

console translator:generate-cache

5) Configure navigation

Update the analytics navigation entry in config/Zed/navigation.xml to add Search Statistics as a sub-page. Replace the existing <analytics> entry with the following:

config/Zed/navigation.xml

<analytics>
    <label>Analytics</label>
    <title>Analytics</title>
    <icon>bar_chart_4_bars</icon>
    <pages>
        <analytics>
            <label>Analytics</label>
            <title>Analytics</title>
            <bundle>analytics-gui</bundle>
            <controller>analytics</controller>
            <action>index</action>
        </analytics>
        <google-analytics>
            <label>Search Statistics</label>
            <title>Search Statistics</title>
            <bundle>google-analytics</bundle>
            <controller>search-statistics</controller>
            <action>index</action>
        </google-analytics>
    </pages>
</analytics>

Generate the router and navigation caches:

console router:cache:warm-up:backoffice
console navigation:build-cache
Verification

Log in to the Back Office and verify that Analytics > Search Statistics appears as a sub-item in the main navigation sidebar.

6) Configure TypeScript paths

In tsconfig.yves.json, add the TraceableEventWidget path alias to compilerOptions.paths:

tsconfig.yves.json

{
    "compilerOptions": {
        "paths": {
            "TraceableEventWidget/*": [
                "./vendor/spryker-shop/traceable-event-widget/src/SprykerShop/Yves/TraceableEventWidget/Theme/default/*"
            ]
        }
    }
}

7) Set up behavior

7.1) Synchronize configuration definitions

Import the Search Statistics configuration schema into the Configuration module:

console configuration:sync
Verification
  1. Log in to the Back Office.
  2. Navigate to Configuration.
  3. In the sidebar, select Integrations and open the Google Analytics tab. Verify that it contains the Storefront Tracking and Data API Connection groups.

7.2) Configure Google Analytics 4 credentials

Before you configure the Back Office, obtain the following parameters from Google:

Configure the Google Analytics 4 connection in the Back Office:

  1. In the Back Office, go to Configuration, select Integrations in the sidebar, and open the Google Analytics tab.
  2. In Storefront Tracking, set the Measurement ID (for example, G-XXXXXXXXXX).
  3. In Data API Connection, set the Property ID and paste the complete JSON content of your Google Cloud service account key into Service Account Credentials JSON.
  4. In Event Tracking > Product Events, enable Search. The storefront sends search events to GA4 only when this event is enabled. For details, see Google Analytics Event Tracking.
Verification
  1. Open the storefront and perform a search.
  2. Verify that a search_results event appears in the Google Analytics 4 DebugView for the configured property. To enable and use DebugView, see Monitor events with DebugView in the Google Analytics Help Center.
  3. Navigate to Analytics > Search Statistics in the Back Office and verify that search term data is returned after the GA4 processing delay (up to 48 hours).