-
Notifications
You must be signed in to change notification settings - Fork 190
Expand file tree
/
Copy pathcourse.js
More file actions
44 lines (40 loc) · 1.71 KB
/
course.js
File metadata and controls
44 lines (40 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { createEventTracker, createLinkTracker } from 'data/services/segment/utils';
import { categories, eventNames } from '../constants';
import * as module from './course';
// Utils/Helpers
/**
* Generate a segement event tracker for a given course event.
* @param {string} eventName - segment event name
* @param {string} courseId - course run identifier
* @param {[object]} options - optional event data
*/
export const courseEventTracker = (eventName, courseId, options = {}) => createEventTracker(
eventName,
{ category: categories.dashboard, label: courseId, ...options },
);
/**
* Generate a hook to allow components to provide a courseId and link href and provide
* a link tracker with defined event name and options, over a set of default optiosn.
* @param {string} eventName - event name for the click event
* @return {callback} - component hook returning a link tracking event callback
*/
export const courseLinkTracker = (eventName) => (courseId, href) => (
createLinkTracker(module.courseEventTracker(eventName, courseId), href)
);
// Non-Link events
export const courseOptionsDropdownClicked = (courseId) => (
module.courseEventTracker(eventNames.courseOptionsDropdownClicked, courseId)
);
// Link events (track and then change page location)
export const courseImageClicked = (...args) => (
module.courseLinkTracker(eventNames.courseImageClicked)(...args));
export const courseTitleClicked = (...args) => (
module.courseLinkTracker(eventNames.courseTitleClicked)(...args));
export const enterCourseClicked = (...args) => (
module.courseLinkTracker(eventNames.enterCourseClicked)(...args));
export default {
courseImageClicked,
courseOptionsDropdownClicked,
courseTitleClicked,
enterCourseClicked,
};