Skip to content

Instantly share code, notes, and snippets.

@eseQ
Created February 12, 2020 10:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eseQ/8040ea13395cbb0feb4512273f0911d0 to your computer and use it in GitHub Desktop.
Save eseQ/8040ea13395cbb0feb4512273f0911d0 to your computer and use it in GitHub Desktop.
import React from 'react';
import { canUseDOM } from 'react-eq-utilities/dom';
const WINDOW = canUseDOM ? window : {};
const Image = ({ id }) => {
if (!id) return null;
return (
<a
href={`https://top.mail.ru/jump?from=${id}`}
target="_blank"
rel="noopener noreferrer nofollow"
>
<img
src={`//top-fwz1.mail.ru/counter?id=${id};t=617;l=1`}
style={{ border: 0 }}
height={40}
width={88}
alt="Рейтинг@Mail.ru"
/>
</a>
);
};
const noscriptStyle = { border: 0, position: 'absolute', left: -9999, top: -9999 };
export default (id = WINDOW.tmrId) => ({
tmr: WINDOW._tmr || (WINDOW._tmr = []),
noscript() {
return (
<noscript>
<img
src={`https://top-fwz1.mail.ru/counter?id=${id};js=na`}
style={noscriptStyle}
alt="Top.Mail.Ru"
/>
</noscript>
);
},
push(params) {
const p = { ...params };
if (!WINDOW.TMRstart) {
p.start = (new Date()).getTime();
WINDOW.TMRstart = true;
}
return this.tmr.push({ id, type: 'pageView', ...p });
},
init() {
const exist = document.getElementById('topmailru-code');
const tmr = WINDOW._tmr || (WINDOW._tmr = []);
WINDOW.tmrId = id;
// tmr.push({ id, type: 'pageView', start: (new Date()).getTime() });
if (exist) return;
const s = document.createElement('script');
s.async = true;
s.src = `http${(document.location.protocol === 'https:' ? 's' : '')}://top-fwz1.mail.ru/js/code.js`;
s.id = 'topmailru-code';
const head = document.head;
if (head) head.appendChild(s);
},
image: () => <Image id={id || WINDOW.tmrId || WINDOW._tmr[0]} />,
});
@eseQ
Copy link
Author

eseQ commented Feb 12, 2020

При инициализации первой страницы вызывается метов init.
При переходе по страницам осуществляется вызов метода push с параметрами.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment