Advertisement
briank

Sanitize WJ/EW Personal Info From URL Query String

Jul 6th, 2021 (edited)
3,773
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * Sanitize WJ/EW lead personal info from query string
  3.  * after moving the values to local storage.
  4.  * Run before recording Facebook events.
  5.  * Author: Brian Katzung
  6.  */
  7. (function () {
  8.     var ls = location.search, params = [], reset = false;
  9.     ls && ls.substring(1).split('&').forEach(function (param) {
  10.     var parts = param.match(/([^=]+)=(.*)/);
  11.     if (parts[1].match(/^wj_lead_/)) {
  12.         localStorage.setItem(parts[1], decodeURIComponent(parts[2].replaceAll('+', ' ')));
  13.         reset = true;
  14.     } else {
  15.         params.push(param);
  16.     }
  17.     });
  18.     if (reset) {
  19.         var newSearch = '?' + params.join('&');
  20.         if (history.replaceState) history.replaceState(null, '', newSearch);
  21.         else location.search = newSearch;
  22.     }
  23. })();
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement