Skip to content

Commit

Permalink
Add video provider tracking (MailOnline#23)
Browse files Browse the repository at this point in the history
Add client config
  • Loading branch information
iq-dot authored Jun 28, 2017
1 parent 3322f9d commit 6140350
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ class App extends React.Component {
poster: fields.poster[0],
title: fields.title[0],
description: fields.description[0],
provider: fields.provider[0],
videoId: video.id,
});
});
Expand Down Expand Up @@ -213,6 +214,7 @@ class App extends React.Component {
player_duration: Math.ceil(player.duration()),
player_src: player.currentSrc(),
player_poster: player.poster(),
video_provider: player.playlist()[player.playlist.currentItem()].provider,
title: player.playlist()[player.playlist.currentItem()].title,
website_url: window.location.href,
website_domain: window.location.hostname,
Expand Down
55 changes: 55 additions & 0 deletions src/client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const CONFIG = {
'telegraph': {
selector: 'article[itemprop=articleBody]'
},
'nigella': {
selector: 'section.details'
}
}

/**
* Retrieve the current client based on the current URL we are in
* @returns {*}
*/
export function getClient() {
const href = window.location.href;

if (urlMatch('localhost')) return 'localhost';
if (urlMatch(['delta.sugges.tv/test/index', 'build.suggestv.io/test/index', 'build.suggestv.io/test/cjallen'])) return 'test';
if (urlMatch(['delta.sugges.tv/test', 'build.suggestv.io/test'])) return 'client-test';
if (urlMatch('telegraph.co.uk')) return 'telegraph';
if (urlMatch('londontheinside.com')) return 'londontheinside';
if (urlMatch('beautyandthedirt.com')) return 'beautyandthedirt';
if (urlMatch('bristol-sport.co.uk')) return 'bristolsport';
if (urlMatch('proactiveinvestors.co.uk')) return 'proactiveinvestors';
if (urlMatch('advfn.com')) return 'advfn';
if (urlMatch('hospitalitytrends.net')) return 'hospitalitytrends';
if (urlMatch('prospectmagazine.co.uk')) return 'prospectmagazine';
if (urlMatch('spectator.co.uk')) return 'spectator';
if (urlMatch('cityam.com')) return 'cityam';
if (urlMatch('hitc.com')) return 'hitc';
if (urlMatch('zmescience.com')) return 'sovrnus';
if (urlMatch(['livingly.com', 'independent.ie'])) return 'sovrnuk';
if (urlMatch('clickon.co')) return 'clickon';
if (urlMatch(['lbc.co.uk', 'classicfm.com', 'capitalfm.com', 'heart.co.uk', 'lbc.utest'])) return 'global-radio';
if (urlMatch('nigella.com')) return 'nigella';

function urlMatch(url) {
return Array.isArray(url)
? url.some(u => href.indexOf(u) !== -1)
: href.indexOf(url) !== -1;
}

return 'unknown';
}

/**
* Returns a client specific page selector if there is one otherwise null
* @param {elem} client
*/
export function getPageSelector(client) {
const config = CONFIG[client] || {};
const selector = config.selector;

return selector ? document.querySelector(selector) : null;
}

0 comments on commit 6140350

Please sign in to comment.