diff --git a/source/containers/Layout.js b/source/containers/Layout.js index 29da40d87..e6912a9b6 100644 --- a/source/containers/Layout.js +++ b/source/containers/Layout.js @@ -17,12 +17,21 @@ import About from 'Components/pages/About' import ReactPiwik from 'Components/Tracker' import createHistory from 'history/createBrowserHistory' import Header from 'Components/pages/Header' +import { getIframeOption } from '../utils' const piwik = new ReactPiwik({ url: 'stats.data.gouv.fr', siteId: 39, trackErrors: true }) +let integratorUrl = getIframeOption('integratorUrl') +ReactPiwik.push([ + 'setCustomVariable', + 1, + 'urlPartenaire', + decodeURIComponent(integratorUrl || 'https://embauche.beta.gouv.fr'), + 'visit' +]) export default class Layout extends Component { history = createHistory() diff --git a/source/entry.js b/source/entry.js index af010aff9..37c45582d 100644 --- a/source/entry.js +++ b/source/entry.js @@ -6,14 +6,11 @@ import reducers from './reducers' import DevTools from './DevTools' import { AppContainer } from 'react-hot-loader' import computeThemeColours from './components/themeColours' +import { getIframeOption, getUrl } from './utils' -let url = window.location.href.toString(), - urlColour = url.includes('couleur=') let initialStore = { - iframe: url.includes('iframe'), - themeColours: computeThemeColours( - urlColour && url.split('couleur=')[1].split('&')[0] - ) + iframe: getUrl().includes('iframe'), + themeColours: computeThemeColours(getIframeOption('couleur')) } let store = createStore(reducers, initialStore, compose(DevTools.instrument())) diff --git a/source/iframe-script.js b/source/iframe-script.js index 896b9bcdd..730cf0777 100644 --- a/source/iframe-script.js +++ b/source/iframe-script.js @@ -1,10 +1,11 @@ // Get the "couleur" parameter passed to this script let script = document.getElementById('script-simulateur-embauche'), couleur = script.dataset['couleur'], - src = script.getAttribute('src') + src = script.getAttribute('src'), + integratorUrl = encodeURIComponent(window.location.href.toString()) document.write(` +}?couleur=${couleur}&iframe&integratorUrl=${integratorUrl}" style="border: none; width: 100%; display: block; margin: 0 auto; height: 45em" allowfullscreen webkitallowfullscreen mozallowfullscreen> `) diff --git a/source/utils.js b/source/utils.js index 46f503eb0..8781c7c88 100644 --- a/source/utils.js +++ b/source/utils.js @@ -1 +1,8 @@ export let capitalise0 = name => name[0].toUpperCase() + name.slice(1) + +export let getUrl = () => window.location.href.toString() +export let getIframeOption = optionName => { + let url = getUrl(), + hasOption = url.includes(optionName + '=') + return hasOption && url.split(optionName + '=')[1].split('&')[0] +}