public optIn()

in src/shippers/fullstory/src/fullstory_shipper.ts [193:227]


  public optIn(isOptedIn: boolean): void {
    this.initContext.logger.debug(`Setting FS to optIn ${isOptedIn}`);
    // FullStory uses 2 different opt-in methods:
    // - `consent` is needed to allow collecting information about the components
    //   declared as "Record with user consent" (https://help.fullstory.com/hc/en-us/articles/360020623574).
    //   We need to explicitly call `consent` if for the "Record with user content" feature to work.
    this.fullStoryApi('setIdentity', { consent: isOptedIn });
    // - `restart` and `shutdown` fully start/stop the collection of data.
    if (isOptedIn) {
      // When using the delayed startup strategy...
      if (this.delayedStartup) {
        // ... it is recommended to identify the user before enabling capture to avoid duplicated sessions
        // when navigating across multiple domains (Cloud UI <-> Deployment 1 <-> Deployment 2 <-> Project 1).

        // If the user is already present, we can start/resume the capture straight away.
        if (this.lastUserId) {
          if (this.optedIn === false) {
            // when previously shut down => restart
            // https://developer.fullstory.com/browser/auto-capture/capture-data/#restart-data-capture
            this.fullStoryApi('restart');
          } else {
            this.fullStoryApi('start');
          }
        }
      } else {
        this.fullStoryApi('restart');
      }
    } else {
      this.fullStoryApi('shutdown');
    }

    // Storing the state because it's necessary to find out whether to start/restart,
    // and it's used to explicitly start after the user is identified in delayedStartup mode.
    this.optedIn = isOptedIn;
  }