-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
880 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
define([ | ||
'underscore', | ||
'jquery', | ||
'js/components/generic_module', | ||
'js/mixins/dependon', | ||
'analytics', | ||
'js/components/pubsub_events', | ||
], function(_, $, GenericModule, Dependon, analytics, PubsubEvents) { | ||
var Experiments = GenericModule.extend({ | ||
initialize: function() { | ||
// store all metadata entries here | ||
this.isRunning = false; | ||
}, | ||
|
||
activate: function(beehive, app) { | ||
this.setApp(app); | ||
this.setBeeHive(beehive); | ||
var pubsub = this.getPubSub(); | ||
|
||
if (!window.gtag) { | ||
window.gtag = function() { | ||
if (_.isArray(window.dataLayer)) { | ||
window.dataLayer.push(arguments); | ||
} | ||
}; | ||
window.gtag('event', 'optimize.callback', { | ||
callback: (value, name) => { | ||
console.log( | ||
'Experiment with ID: ' + name + ' is on variant: ' + value | ||
); | ||
}, | ||
}); | ||
} | ||
|
||
pubsub.subscribe( | ||
pubsub.APP_BOOTSTRAPPED, | ||
_.bind(this.onAppStarted, this) | ||
); | ||
if (false) { | ||
pubsub.subscribe(pubsub.NAVIGATE, function(id) { | ||
if (id === 'SearchWidget') { | ||
window.bbb.getWidget('RecommenderWidget').then(function(w) { | ||
window.r = w; | ||
var { tab } = w.getState(); | ||
// activate recommendations | ||
if (!tab !== 1) { | ||
w.dispatch({ type: 'SET_TAB', payload: 1 }); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
}, | ||
|
||
/** | ||
* | ||
* callback that can be used by external components; they can listen to BBB and then run their experiment | ||
* | ||
* */ | ||
subscribe: function(event, callback) { | ||
var pubsub = this.getPubSub(); | ||
if (PubsubEvents[event]) { | ||
pubsub.subscribe(PubsubEvents[event], callback); | ||
} | ||
}, | ||
|
||
subscribeOnce: function(event, callback) { | ||
var pubsub = this.getPubSub(); | ||
if (PubsubEvents[event]) { | ||
pubsub.subscribeOnce(PubsubEvents[event], callback); | ||
} | ||
}, | ||
|
||
onAppStarted: function() { | ||
this.toggleOptimize(); | ||
}, | ||
|
||
toggleOptimize: function() { | ||
if (!window.dataLayer) { | ||
console.warn( | ||
'Optimize is not available, we are not running any experiment' | ||
); | ||
return; | ||
} | ||
|
||
if (this.isRunning) { | ||
window.dataLayer.push({ event: 'optimize.deactivate' }); | ||
} else { | ||
window.dataLayer.push({ event: 'optimize.activate' }); | ||
} | ||
this.isRunning = !this.isRunning; | ||
}, | ||
}); | ||
_.extend(Experiments.prototype, Dependon.BeeHive, Dependon.App); | ||
|
||
return Experiments; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
define([], function() { | ||
const actions = { | ||
GET_RECOMMENDATIONS: 'GET_RECOMMENDATIONS', | ||
GET_DOCS: 'GET_DOCS', | ||
SET_DOCS: 'SET_DOCS', | ||
SET_QUERY: 'SET_QUERY', | ||
UPDATE_SEARCH_BAR: 'UPDATE_SEARCH_BAR', | ||
GET_FULL_LIST: 'GET_FULL_LIST', | ||
EMIT_ANALYTICS: 'EMIT_ANALYTICS', | ||
SET_TAB: 'SET_TAB', | ||
SET_ORACLE_TARGET: 'SET_ORACLE_TARGET', | ||
SET_QUERY_PARAMS: 'SET_QUERY_PARAMS', | ||
}; | ||
|
||
const actionCreators = { | ||
getRecommendations: () => ({ | ||
type: actions.GET_RECOMMENDATIONS, | ||
}), | ||
getDocs: (query) => ({ | ||
type: 'API_REQUEST', | ||
scope: actions.GET_DOCS, | ||
options: { | ||
type: 'GET', | ||
target: 'search/query', | ||
query, | ||
}, | ||
}), | ||
setDocs: (docs) => ({ | ||
type: actions.SET_DOCS, | ||
payload: docs, | ||
}), | ||
setQuery: (query) => ({ | ||
type: actions.SET_QUERY, | ||
payload: query, | ||
}), | ||
setQueryParams: (payload) => ({ | ||
type: actions.SET_QUERY_PARAMS, | ||
payload, | ||
}), | ||
updateSearchBar: (text) => ({ | ||
type: actions.UPDATE_SEARCH_BAR, | ||
payload: text, | ||
}), | ||
getFullList: () => ({ | ||
type: actions.GET_FULL_LIST, | ||
}), | ||
emitAnalytics: (payload) => ({ | ||
type: actions.EMIT_ANALYTICS, | ||
payload, | ||
}), | ||
setTab: (tab) => ({ | ||
type: actions.SET_TAB, | ||
payload: tab, | ||
}), | ||
setOracleTarget: (target) => ({ | ||
type: actions.SET_ORACLE_TARGET, | ||
payload: target, | ||
}), | ||
}; | ||
|
||
return { ...actions, ...actionCreators }; | ||
}); |
Oops, something went wrong.