Caching issue caused by the ability for the user to opt in/out scripts

Created on 18 July 2024, 4 months ago

Problem/Motivation

There is an option to allow the user to decide if they want to opt in/out of the scripts.

When this option is enabled, there is a field in the user page that allow the user to change the value and decide.

The problem is that the condition is being evaluated in the back end and by setting cache contexts per user, it means that we will have user ids on the cache tags of every page that has the VWO scripts.
This is bad for performance because it will cause a log of cache misses.
Every time an authenticated user visits a page, an entry of user id will be added to the cache tags.
If one user changes their view options, every page that is tagged with that user will be flushed.
This is bad for large sites that have large number of articles and users because the cache tags will be massive.

Steps to reproduce

  1. Enable and configure VWO to allow users to opt in/out of VWO scripts
  2. Visit the user profile and update the VWO option
  3. Visit a page where the VWO script is included
  4. Check the cache tags in the cache_render table, see screenshot below. Observe that the user id is added to every cache entry

Proposed resolution

Part 1: We need to stop adding cache tags in the back end. Ideally this could be done in one of the following methods:

  1. Using cookies: The value of the option in the user profile can be stored as a cookie on the front end. This could be bad option for users that disable cookies
  2. Using browser's local storage: The value of the option in the user profile is stored in the user's browser. If the user uses another computer or another browser, the value will be fetched again from the account and stored on that browser.
  3. Using Drupal Settings: The user data can be added to the page using DrupalSettings. This option needs to be explored to make sure we don't cache the respective settings.

Part 2: We need to update the bootstrap script to check the user personal option first, before sending any data to VWO. The script can still be on the page, but no data will be sent if the user decides not to. See code https://git.drupalcode.org/project/vwo/-/blob/8.x-1.x/vwo.module?ref_typ...

Make sure the code is compatible with Drupal 11

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇬🇧United Kingdom marcelovani London

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

Comments & Activities

Production build 0.71.5 2024