Skip to content

Commit 6140350

Browse files
authored
Add video provider tracking (MailOnline#23)
Add client config
1 parent 3322f9d commit 6140350

2 files changed

Lines changed: 57 additions & 0 deletions

File tree

src/App.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ class App extends React.Component {
146146
poster: fields.poster[0],
147147
title: fields.title[0],
148148
description: fields.description[0],
149+
provider: fields.provider[0],
149150
videoId: video.id,
150151
});
151152
});
@@ -213,6 +214,7 @@ class App extends React.Component {
213214
player_duration: Math.ceil(player.duration()),
214215
player_src: player.currentSrc(),
215216
player_poster: player.poster(),
217+
video_provider: player.playlist()[player.playlist.currentItem()].provider,
216218
title: player.playlist()[player.playlist.currentItem()].title,
217219
website_url: window.location.href,
218220
website_domain: window.location.hostname,

src/client.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
const CONFIG = {
2+
'telegraph': {
3+
selector: 'article[itemprop=articleBody]'
4+
},
5+
'nigella': {
6+
selector: 'section.details'
7+
}
8+
}
9+
10+
/**
11+
* Retrieve the current client based on the current URL we are in
12+
* @returns {*}
13+
*/
14+
export function getClient() {
15+
const href = window.location.href;
16+
17+
if (urlMatch('localhost')) return 'localhost';
18+
if (urlMatch(['delta.sugges.tv/test/index', 'build.suggestv.io/test/index', 'build.suggestv.io/test/cjallen'])) return 'test';
19+
if (urlMatch(['delta.sugges.tv/test', 'build.suggestv.io/test'])) return 'client-test';
20+
if (urlMatch('telegraph.co.uk')) return 'telegraph';
21+
if (urlMatch('londontheinside.com')) return 'londontheinside';
22+
if (urlMatch('beautyandthedirt.com')) return 'beautyandthedirt';
23+
if (urlMatch('bristol-sport.co.uk')) return 'bristolsport';
24+
if (urlMatch('proactiveinvestors.co.uk')) return 'proactiveinvestors';
25+
if (urlMatch('advfn.com')) return 'advfn';
26+
if (urlMatch('hospitalitytrends.net')) return 'hospitalitytrends';
27+
if (urlMatch('prospectmagazine.co.uk')) return 'prospectmagazine';
28+
if (urlMatch('spectator.co.uk')) return 'spectator';
29+
if (urlMatch('cityam.com')) return 'cityam';
30+
if (urlMatch('hitc.com')) return 'hitc';
31+
if (urlMatch('zmescience.com')) return 'sovrnus';
32+
if (urlMatch(['livingly.com', 'independent.ie'])) return 'sovrnuk';
33+
if (urlMatch('clickon.co')) return 'clickon';
34+
if (urlMatch(['lbc.co.uk', 'classicfm.com', 'capitalfm.com', 'heart.co.uk', 'lbc.utest'])) return 'global-radio';
35+
if (urlMatch('nigella.com')) return 'nigella';
36+
37+
function urlMatch(url) {
38+
return Array.isArray(url)
39+
? url.some(u => href.indexOf(u) !== -1)
40+
: href.indexOf(url) !== -1;
41+
}
42+
43+
return 'unknown';
44+
}
45+
46+
/**
47+
* Returns a client specific page selector if there is one otherwise null
48+
* @param {elem} client
49+
*/
50+
export function getPageSelector(client) {
51+
const config = CONFIG[client] || {};
52+
const selector = config.selector;
53+
54+
return selector ? document.querySelector(selector) : null;
55+
}

0 commit comments

Comments
 (0)