Solved

Page wise configuration in a SPA

  • 27 February 2023
  • 6 replies
  • 93 views

Userlevel 1
Badge +1

How can I stop tracking/re-initialize heap in certain pages in a single page application? I need to configure ‘disableTextCapture’ based on pages. 

icon

Best answer by jonathan 27 February 2023, 19:47

View original

6 replies

Userlevel 3
Badge +3

Hi Sujan, did you see Using Heap With Single Page Application (SPA) Websites?

Userlevel 1
Badge +1

Yes, but I couldn’t find anything useful for my problem.

Userlevel 5
Badge +3

Hey @sujan — We don’t have first class support for this today. Stopping/start tracking can be done by manually setting `heap.loaded` to `false` and `true`. (It’s for internal usage, set to `true` once Heap has loaded, but this happens to work if you really need to do it.). This works as long as your use case is actually stopping tracking, but not if your use case is changing the config. 

There’s currently no way to change the `heap.config` outside of calling `heap.load`, and you can’t call that twice in the same js context. We don’t currently support arbitrarily changing the privacy configs from the client after Heap loads for security reasons. However, I’ve shared this feedback with the heapjs team for future development consideration.

Userlevel 1
Badge +1

Thank you @jonathan  for taking a look into this.

Badge +1

@jonathan Am I correct in concluding this heap.loaded = false flag is not respected anymore? 

Running heap v4.19.3, setting this flag does stop all requests to the usual https://heapanalytics.com/h endpoint. However, auryc.worker.js keeps sending data to mt.auryc.com/v1/event.

I’d really like to unload Heap altogether when my records show a customer has asked to opt out of any behavior tracking.

Userlevel 5
Badge +3

@trevdor `heap.loaded = false` just happens to work to stop event data capture because of Heap internals, it’s not an official API to “unload” Heap. 

It sounds like your use case would be better solved with a cookie consent tool or similar behavior, where Heap is gated behind consent and conditionally loaded on that basis. Typically, when consent is revoked, those tools refresh the page and simply don’t load the snippet. That would be my recommendation. 

Reply