Advertisement
fionchangla

tracking search with filters

Dec 12th, 2023
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. <script>
  2. function getContentStatusLabel(status_id) {
  3. switch(status_id){
  4. case '121':
  5. return 'Open';
  6. case '125':
  7. return 'Closed';
  8. case '124':
  9. return 'Closed with follow up';
  10. default:
  11. return status_id;
  12. }
  13. }
  14. function getTopicLabel(topic_id) {
  15. switch(topic_id){
  16. case '92':
  17. return 'Arts and culture';
  18. case '95':
  19. return 'Communities';
  20. case '96':
  21. return 'Planning and regeneration';
  22. case '99':
  23. return 'Economy';
  24. case '100':
  25. return 'Skills and education';
  26. case '101':
  27. return 'Environment';
  28. case '103':
  29. return 'Health';
  30. case '105':
  31. return 'Housing';
  32. case '108':
  33. return 'Police';
  34. case '109':
  35. return 'Fire';
  36. case '110':
  37. return 'Transport';
  38. case '113':
  39. return 'Recovery from COVID-19';
  40. default:
  41. return topic_id;
  42. }
  43. }
  44. var params = new URLSearchParams(window.location.search);
  45. if (params && params.size !==0) {
  46. var customSearchData = {
  47. 's' : '',
  48. 'field_content_status' : [],
  49. 'field_topic' : [],
  50. 'type' : [],
  51. 'dates' : []
  52. };
  53. var keys = Array.from(params.keys());
  54. keys.forEach(function(key){
  55. var value = params.get(key);
  56. if (key == 's') {
  57. customSearchData['s'] = value;
  58. }
  59. else if (key.indexOf('field_content_status') !== -1) {
  60. customSearchData['field_content_status'].push(getContentStatusLabel(value));
  61. }
  62. else if (key.indexOf('field_topic') !== -1) {
  63. customSearchData['field_topic'].push(getTopicLabel(value));
  64. }
  65. else if (key.indexOf('type') !== -1) {
  66. if (value == 'forum') {
  67. value = 'discussion';
  68. }
  69. customSearchData['type'].push(value);
  70. }
  71. else if (key.indexOf('created') !== -1 && value != '') {
  72. customSearchData['dates'].push(value);
  73. }
  74. });
  75.  
  76. window.dataLayer.push({
  77. event: 'talk_london_search_data',
  78. talk_london_search_data: customSearchData['s'],
  79. field_content_status: customSearchData['field_content_status'],
  80. field_topic: customSearchData['field_topic'],
  81. type: customSearchData['type'],
  82. dates: customSearchData['dates']
  83. });
  84. }
  85.  
  86. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement