Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var categories = {
- UI_ACTION: 'ui_action',
- CLIENT_INFO: 'client_info'
- };
- var events = {
- 'DATE_BUTTON': {
- category: categories.UI_ACTION,
- action: 'date_button'
- },
- 'PASSENGERS_BUTTON': {
- category: categories.UI_ACTION,
- action: 'passengers_button'
- },
- 'SEARCH_BUTTON': {
- category: categories.UI_ACTION,
- action: 'search_button'
- },
- 'SORT_BUTTON': {
- category: categories.UI_ACTION,
- action: 'sort_button',
- label: 'byTime' // byTime || byPrice || byDuration
- },
- 'SEARCH_LOADMORE': {
- category: categories.UI_ACTION,
- action: 'search_loadmore'
- },
- 'SELECT_ROUTE': {
- category: categories.UI_ACTION,
- action: 'select_route'
- },
- 'SELECT_DETAILS_TAB': {
- category: categories.UI_ACTION,
- action: 'select_details_tab',
- label: 'Stations' // Stations || Prices || Map
- },
- 'BUY_BUTTON': {
- category: categories.UI_ACTION,
- action: 'buy_button'
- },
- 'BUY_CONFIRM': {
- category: categories.UI_ACTION,
- action: 'buy_confirm',
- label: 'one-way' // one-way || return
- },
- 'SHARE_BUTTON': {
- category: categories.UI_ACTION,
- action: 'share_button'
- },
- 'ANDROID_LINK': {
- category: categories.UI_ACTION,
- action: 'android_link'
- },
- 'IOS_LINK': {
- category: categories.UI_ACTION,
- action: 'ios_link'
- },
- 'INFO_LINK': {
- category: categories.UI_ACTION,
- action: 'info_link'
- },
- // LOADING
- 'BROWSER_NOT_SUPPORTED': {
- category: categories.CLIENT_INFO,
- action: 'browser_not_supported'
- },
- 'BROWSER_TYPE': {
- category: categories.CLIENT_INFO
- }
- };
- function track(eventType,options) {
- var event = events[eventType];
- if (event) {
- options = options || {};
- var category = event.category;
- var action = options.action || event.action;
- var label = options.label || event.label;
- var ga_args_string = "'"+category+"'";
- var ga_args = ['send','event',category];
- if (action) {
- ga_args_string += ",'"+action+"'";
- ga_args.push(action);
- }
- if (label) {
- ga_args_string += ",'"+label+"'";
- ga_args.push(label);
- }
- }
- //console.log("ga('send','event',"+ga_args_string+");");
- if (ga) {
- ga.apply(null,ga_args);
- }
- }
- function trackSync(eventType,options) {
- if (ga) {
- ga(function(){
- track(eventType,options);
- if (options.cbk) {
- options.cbk ();
- }
- })
- }
- }
- module.exports = {
- track: track,
- trackSync: trackSync
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement