Advertisement
Guest User

Untitled

a guest
May 24th, 2018
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var categories = {
  2.   UI_ACTION: 'ui_action',
  3.   CLIENT_INFO: 'client_info'
  4. };
  5.  
  6. var events = {
  7.   'DATE_BUTTON': {
  8.     category: categories.UI_ACTION,
  9.     action: 'date_button'
  10.   },
  11.   'PASSENGERS_BUTTON': {
  12.     category: categories.UI_ACTION,
  13.     action: 'passengers_button'
  14.   },
  15.   'SEARCH_BUTTON': {
  16.     category: categories.UI_ACTION,
  17.     action: 'search_button'
  18.   },
  19.   'SORT_BUTTON': {
  20.     category: categories.UI_ACTION,
  21.     action: 'sort_button',
  22.     label: 'byTime' // byTime || byPrice || byDuration
  23.   },
  24.   'SEARCH_LOADMORE': {
  25.     category: categories.UI_ACTION,
  26.     action: 'search_loadmore'
  27.   },
  28.   'SELECT_ROUTE': {
  29.     category: categories.UI_ACTION,
  30.     action: 'select_route'
  31.   },
  32.   'SELECT_DETAILS_TAB': {
  33.     category: categories.UI_ACTION,
  34.     action: 'select_details_tab',
  35.     label: 'Stations' // Stations || Prices || Map
  36.   },
  37.   'BUY_BUTTON': {
  38.     category: categories.UI_ACTION,
  39.     action: 'buy_button'
  40.   },
  41.   'BUY_CONFIRM': {
  42.     category: categories.UI_ACTION,
  43.     action: 'buy_confirm',
  44.     label: 'one-way' // one-way || return
  45.   },
  46.   'SHARE_BUTTON': {
  47.     category: categories.UI_ACTION,
  48.     action: 'share_button'
  49.   },
  50.   'ANDROID_LINK': {
  51.     category: categories.UI_ACTION,
  52.     action: 'android_link'
  53.   },
  54.   'IOS_LINK': {
  55.     category: categories.UI_ACTION,
  56.     action: 'ios_link'
  57.   },
  58.   'INFO_LINK': {
  59.     category: categories.UI_ACTION,
  60.     action: 'info_link'
  61.   },
  62.   // LOADING
  63.   'BROWSER_NOT_SUPPORTED': {
  64.     category: categories.CLIENT_INFO,
  65.     action: 'browser_not_supported'
  66.   },
  67.   'BROWSER_TYPE': {
  68.     category: categories.CLIENT_INFO
  69.   }
  70. };
  71.  
  72. function track(eventType,options) {
  73.   var event = events[eventType];
  74.   if (event) {
  75.     options = options || {};
  76.     var category = event.category;
  77.     var action = options.action || event.action;
  78.     var label = options.label || event.label;
  79.     var ga_args_string = "'"+category+"'";
  80.     var ga_args = ['send','event',category];
  81.     if (action) {
  82.       ga_args_string += ",'"+action+"'";
  83.       ga_args.push(action);
  84.     }
  85.     if (label) {
  86.       ga_args_string += ",'"+label+"'";
  87.       ga_args.push(label);
  88.     }
  89.   }
  90.   //console.log("ga('send','event',"+ga_args_string+");");
  91.   if (ga) {
  92.     ga.apply(null,ga_args);
  93.   }
  94. }
  95.  
  96. function trackSync(eventType,options) {
  97.   if (ga) {
  98.     ga(function(){
  99.       track(eventType,options);
  100.       if (options.cbk) {
  101.         options.cbk ();
  102.       }
  103.     })
  104.   }
  105. }
  106.  
  107. module.exports = {
  108.   track: track,
  109.   trackSync: trackSync
  110. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement