React Storefront |

Predictive Prefetching with GA

When using this feature, the next page is predicted and prefetched. This is done by analyzing Google Analytics data and guessing which page is most likely to be navigated to next.

How to setup

Add the client side webpack plugin

This will trigger a Google authentication prompt during the build phase since it is downloading the data for predictions.

const createPlugin = require('react-storefront-extensions/predict-plugin')

module.exports = prod(path.join(__dirname, '..', '..'), {
  ...
  additionalPlugins: [
    createPlugin({ gaViewId: '...' })
  ]
  ...
})

Add the prediction handler

After launching the client, listen for route changes and predict the next route with the given handler.

...
import prefetchPredictedRoute from 'react-storefront-extensions/predict'

launchClient({...});

router.on('after', prefetchPredictedRoute)