Guest User

Untitled

a guest
Oct 19th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.97 KB | None | 0 0
  1. (function($) {
  2. $(document).ready(function() {
  3. $(window).load(function() {
  4.  
  5. // Forms based Selectbox GA detection
  6. $('#views-exposed-form-tours-block select, #trip-finder select, #webform-client-form-110').change(function() {
  7.  
  8. // Determine Select form field value
  9. var label = '';
  10. var option = $('option:selected', this).text();
  11. var labelElem = 'label[for=' + $(this).attr('id') + ']';
  12. label = $(labelElem).text()
  13. if (label.length == 0) {
  14. label = $(this).closest('label').text();
  15. }
  16. if (label.length == 0) {
  17. label=$(this).children('option:first').text();
  18. }
  19.  
  20. // Determine Category & Action
  21. var category = '';
  22. var action = 'Filter Option';
  23. if ($(this).attr('id') == 'trip-finder') {
  24. category = 'Navigate';
  25. action = 'Travcoa Journey Navigator';
  26. } else if ($(this).attr('id') == 'webform-client-form-110') {
  27. category = 'Contact';
  28. action = 'Inquiry';
  29. label = 'Reason for Inquiry';
  30. } else {
  31. category = 'Navigate';
  32. }
  33.  
  34. var myData = $.trim(label) + ' - ' + option;
  35.  
  36. // Push
  37. _gaq.push(['_trackEvent', category, action, myData]);
  38. });// end Select GA
  39.  
  40. // Forms based Submit GA detection
  41. $('#views-exposed-form-tours-block, #trip-finder, #mailchimp-lists-user-subscribe-form-newsletter-signup, #mailchimp-lists-user-subscribe-form-newsletter-signup-footer, #mailchimp-lists-user-subscribe-form-newsletter-signup-full, #webform-client-form-6632, #webform-client-form-904, #webform-client-form-3255, #webform-client-form-6162, #webform-client-form-6600, #webform-client-form-111, #webform-client-form-6354, #webform-client-form-6519, #webform-client-form-5678, #webform-client-form-114').submit(function() {
  42. switch ($(this).attr('id')) {
  43. case 'trip-finder':
  44. category = 'Navigate';
  45. action = 'Travcoa Journey Navigator';
  46. myData = 'Submit - Shoe Me Journeys';
  47. break;
  48.  
  49. case 'views-exposed-form-tours-block':
  50. category = 'Navigate';
  51. action = 'Travcoa Journey Navigator';
  52. myData = 'Submit - Clear Filters';
  53. break;
  54.  
  55. case 'mailchimp-lists-user-subscribe-form-newsletter-signup':
  56. category = 'Register';
  57. action = 'Email Signup';
  58. myData = 'Sidebar';
  59. break;
  60.  
  61. case 'mailchimp-lists-user-subscribe-form-newsletter-signup-footer':
  62. category = 'Register';
  63. action = 'Email Signup';
  64. myData = 'Footer';
  65. break;
  66.  
  67. case 'mailchimp-lists-user-subscribe-form-newsletter-signup-full':
  68. category = 'Register';
  69. action = 'Email Signup';
  70. myData = 'Newsletter Signup Link';
  71. break;
  72.  
  73. case 'webform-client-form-6632':
  74. category = 'Register';
  75. action = 'Email Signup';
  76. myData = 'Incredible Kenya Email Signup';
  77. break;
  78.  
  79. case 'webform-client-form-904':
  80. category = 'Request';
  81. action = 'Quote Request';
  82. myData = 'Independent Journey Quote Request';
  83. break;
  84.  
  85. case 'webform-client-form-3255':
  86. category = 'Request';
  87. action = 'Quote Request';
  88. myData = 'journey Application';
  89. break;
  90.  
  91. case 'webform-client-form-6162':
  92. category = 'Request';
  93. action = 'Quote Request';
  94. myData = 'Journey Quote Request';
  95. break;
  96.  
  97. case 'webform-client-form-6600':
  98. category = 'Request';
  99. action = 'Quote Request';
  100. myData = 'Cuba Quote Request';
  101. break;
  102.  
  103. case 'webform-client-form-111':
  104. category = 'Request';
  105. action = 'Consumer Brochure';
  106. myData = '';
  107. break;
  108.  
  109. case 'webform-client-form-6354':
  110. category = 'Request';
  111. action = 'Promotion Earn 2 Get $200';
  112. myData = '';
  113. break;
  114.  
  115. case 'webform-client-form-6519':
  116. category = 'Request';
  117. action = 'Submit Campaign Lander';
  118. myData = '';
  119. break;
  120.  
  121. case 'webform-client-form-5678':
  122. category = 'Request';
  123. action = 'Agent Brochure';
  124. myData = '';
  125. break;
  126.  
  127. case 'webform-client-form-114':
  128. category = 'Request';
  129. action = 'Employment Application';
  130. myData = '';
  131. break;
  132.  
  133. default:
  134. break;
  135. }
  136.  
  137. // Push
  138. _gaq.push(['_trackEvent', category, action, myData]);
  139. }); // end Submit GA
  140.  
  141.  
  142. // href Links based GA detection
  143. $('#node-118 a, #block-menu-block-1 a, #minipanel-left-destinations a, #minipanel-right-destinations a').click(function() {
  144. $(this).parents('div').each(function(index, attrib) {
  145. if (attrib.id.length > 0) {
  146. myElem = attrib.id;
  147. return false;
  148. }
  149. });
  150. switch (myElem) {
  151. case 'node-118':
  152. category = 'Outgoing Link';
  153. action = 'Travelers Links';
  154. myData = $(this).attr('href');
  155. break;
  156.  
  157. case 'block-menu-block-1':
  158. category = 'Navigate';
  159. action = 'Main Navigation';
  160. myData = 'Level 1 - ' + $(this).text();
  161. break;
  162.  
  163. case 'minipanel-left-destinations':
  164. category = 'Navigate';
  165. action = 'Main Navigation';
  166. myData = 'Level 2 - ' + $(this).text();
  167. break;
  168.  
  169. case 'minipanel-right-destinations':
  170. category = 'Navigate';
  171. action = 'Main Navigation';
  172. myData = 'Level 3 - ' + $(this).text();
  173. break;
  174.  
  175. default:
  176. break;
  177. }
  178.  
  179. // Push
  180. _gaq.push(['_trackEvent', category, action, myData]);
  181. }); // end href GA
  182.  
  183. // no results based GA detection
  184. if ($('.tours-no-results').length > 0) {
  185. var sp = ' | ';
  186. var category = 'Error';
  187. var action = 'No Results';
  188. var journey = $('#edit-field-journey-type-tid option:selected').text();
  189. var experience = $('#edit-field-special-interest-tid-selective option:selected').text();
  190. var director = $('#edit-field-tour-director-target-id option:selected').text();
  191. var month = $('#edit-field-departure-dates-value-value-month option:selected').text();
  192. var filters = journey + sp +experience + sp +director + sp + month;
  193. myData = $('#trip-finder-region option:selected').text() + sp + $('#page-title').html() + sp + filters;
  194.  
  195. // Push
  196. _gaq.push(['_trackEvent', category, action, myData]);
  197. }; // end no results GA
  198.  
  199.  
  200. // View Pages based GA detection
  201. urlList = ['/request-brochure',
  202. '/travel-agents',
  203. '/why-travcoa/about-us/press-releases'
  204. ];
  205. if(jQuery.inArray($(location).attr('pathname'), urlList)!==-1 || $(location).attr('pathname').indexOf('/press-releases/')>=0) {
  206. if ($(location).attr('pathname').indexOf('/press-releases/')>=0) {
  207. category = 'View';
  208. action = 'Press Release';
  209. myData = $('#page-title').html();
  210. } else {
  211. category = 'View';
  212. action = $('#page-title').html();
  213. myData = '';
  214. }
  215. // Push
  216. _gaq.push(['_trackEvent', category, action, myData]);
  217. }; // end View GA
  218.  
  219. // Sample Email GA detection
  220. $('.email-sample').click(function() {
  221. category = 'View';
  222. action = 'Sample Email';
  223. myData = '';
  224.  
  225. // Push
  226. _gaq.push(['_trackEvent', category, action, myData]);
  227. }); // end Sample Email GA
  228.  
  229. });
  230. });
  231. })(jQuery);
Add Comment
Please, Sign In to add comment