🐛 Désactive le suivi des actions sur Safari mobile

Uniquement pour les intégration iFrame. Relatif à #893.

Revert de 6d185e et 65a905
pull/917/head
Maxime Quandalle 2020-03-06 14:32:49 +01:00
parent 5c3ee00832
commit fc07701079
No known key found for this signature in database
GPG Key ID: 428641C03D29CA10
2 changed files with 35 additions and 3 deletions

View File

@ -257,6 +257,22 @@
<% if (htmlWebpackPlugin.options.injectTrackingScript) { %>
<script type="text/javascript">
var _paq = window._paq || []
_paq.push([
function() {
var self = this
function getOriginalVisitorCookieTimeout() {
var now = new Date(),
nowTs = Math.round(now.getTime() / 1000),
visitorInfo = self.getVisitorInfo()
var createTs = parseInt(visitorInfo[2])
var cookieTimeout = 33696000 // 13 mois en secondes
var originalTimeout = createTs + cookieTimeout - nowTs
return originalTimeout
}
this.setVisitorCookieTimeout(getOriginalVisitorCookieTimeout())
}
])
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(['setDocumentTitle', document.domain + '/' + document.title])
_paq.push([
@ -297,7 +313,7 @@
-->
<script src="https://polyfill.io/v3/polyfill.min.js?features=Intl.~locale.en%2CIntl.~locale.fr%2CIntersectionObserver"></script>
<% for (var chunk in htmlWebpackPlugin.files.chunks) { %>
<!-- <script nomodule src="<%= chunk %>.legacy.bundle.js"></script> -->
<script nomodule src="<%= chunk %>.legacy.bundle.js"></script>
<% } %>
</body>
</html>

View File

@ -1,5 +1,5 @@
import { History, Location } from 'history'
import { debounce } from './utils'
import { debounce, inIframe } from './utils'
declare global {
interface Window {
@ -10,12 +10,28 @@ declare global {
type PushArgs = ['trackPageView'] | ['trackEvent', ...Array<string | number>]
type PushType = (args: PushArgs) => void
const ua = window.navigator.userAgent
const iOSSafari =
(!!ua.match(/iPad/i) || !!ua.match(/iPhone/i)) &&
!!ua.match(/WebKit/i) &&
!ua.match(/CriOS/i)
export default class Tracker {
push: PushType
unlistenFromHistory: (() => void) | undefined
previousPath: string | undefined
constructor(pushFunction: PushType = args => window._paq.push(args)) {
constructor(
pushFunction: PushType = args => {
// There is an issue with the way Safari handle cookies in iframe, cf.
// https://gist.github.com/iansltx/18caf551baaa60b79206. We could probably
// do better but for now we don't track action of iOs Safari user in
// iFrame -- to avoid errors in the number of visitors in our stats.
if (!(iOSSafari && inIframe)) {
window._paq.push(args)
}
}
) {
if (typeof window !== 'undefined') window._paq = window._paq || []
this.push = debounce(200, pushFunction) as PushType
}