Skip to content

Commit

Permalink
https://github.com/narkq/react-yandex-metrika/issues/15
Browse files Browse the repository at this point in the history
  • Loading branch information
dima117 committed Jun 29, 2018
1 parent 18afeb3 commit a503562
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,28 @@ function ymProxy(id, methodName, ...args) {
}
}

function ymAsyncProxy(...args) {
window[accountListName].forEach(id => {
let trackerVersion = window[trackerVersionName(id)];
let callbackQueue = window[callbackQueueName(trackerVersion)];
if (callbackQueue) {
callbackQueue.push(() => ymProxy(id, ...args));
} else {
ymProxy(id, ...args);
}
});
function ymAsyncProxy(counterId, ...args) {
window[accountListName]
.filter(id => counterId === undefined || counterId == id)
.forEach(id => {
let trackerVersion = window[trackerVersionName(id)];
let callbackQueue = window[callbackQueueName(trackerVersion)];
if (callbackQueue) {
callbackQueue.push(() => ymProxy(id, ...args));
} else {
ymProxy(id, ...args);
}
});
}

function ym(...args) {
ym2(undefined, ...args);
}

// rename it at your discretion
export function ym2(counterId, ...args) {
if (isBrowser) {
ymAsyncProxy(...args);
ymAsyncProxy(counterId, ...args);
}
}

Expand Down

0 comments on commit a503562

Please sign in to comment.