Skip to content

Instantly share code, notes, and snippets.

@DScheglov
Created November 8, 2017 17:08
Show Gist options
  • Save DScheglov/f9d502fccbd7dc46fcb034c98c630b19 to your computer and use it in GitHub Desktop.
Save DScheglov/f9d502fccbd7dc46fcb034c98c630b19 to your computer and use it in GitHub Desktop.
<script type="text/javascript">
if(window.performance && window.performance.timing) {
var dom_content_loaded = (
window.performance.timing.domContentLoadedEventEnd - window.performance.timing.navigationStart
);
var dom_complete = (
window.performance.timing.domComplete - window.performance.timing.navigationStart
);
var payload = {
url: '/api_v3/visit/track?appKey={/literal}{$smarty.const.PDFFILLER_API_KEY}{literal}',
type: 'post',
data: {
user_id: '{/literal}{if isset($user.id)}{$user.id}{else}0{/if}{literal}',
url: window.location.href,
module: '{/literal}{$module}{literal}',
action: '{/literal}{$action}{literal}',
dom_content_loaded: dom_content_loaded,
dom_complete: dom_complete,
}
};
addEvent(window, 'load', function () { ensureJQuery(sendStat); });
}
function sendStat() {
$.ajax(payload, { dataType: 'json', success: handleSuccess });
}
function handleSuccess(json) {
if (json && json.status === 'ok' && json.visit_page_load_id) {
window.visitPageLoadId = json.visit_page_load_id;
if('{/literal}{$module}{literal}' === 'forms') {
window.ActionCreators.Statistic.setVisitPageLoadId();
}
}
}
function ensureJQuery(cb) {
if (window.jQuery == null) {
var s = document.createElement('script');
s.type = 'text/javascript';
s.src = 'https://code.jquery.com/jquery-3.1.0.min.js}';
s.onload = cb;
document.head.appendChild(s);
return;
}
cb();
}
function addEvent(elem, event, fn) {
if (elem.addEventListener) {
elem.addEventListener(event, fn, false);
} else {
elem.attachEvent("on" + event, function() {
return(fn.call(elem, window.event));
});
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment