(function () {
  var eventType = 'visit';
  var incs = [{"time":5000,"name":"5s"},{"time":10000,"name":"10s"},{"time":15000,"name":"15s"},{"time":30000,"name":"30s"},{"time":60000,"name":"60s"},{"time":90000,"name":"90s"},{"time":120000,"name":"120s"}];
  var targetUrl = 'https://ads.sonataplatform.com/pixel/attribution/645cf8dbcf3737001f8a1702';
  var container = document.createElement('div');
  container.id = 'ttAttrib';

  function getSection() {
    if (document.getElementsByTagName('BODY').length > 0) {
      return document.getElementsByTagName('BODY')[0];
    }
    return document.getElementsByTagName('HEAD')[0];
  }

  function insertPixel(event, permanenceTimeMs) {
    var px = document.createElement('img');
    px.src = targetUrl + '?type=' + event + '&permanence=' + permanenceTimeMs + '&ts=' + Date.now();
    px.style = 'position:absolute;top:0;left:-9999px;';
    px.width = 1;
    px.height = 1;

    getSection().appendChild(container);
    document.getElementById('ttAttrib').appendChild(px);
  }

  const initialPermanenceValue = 0;
  insertPixel(eventType, initialPermanenceValue);

  incs.reduce((previousIncTimes, inc) => {
    previousIncTimes.push(inc.time)
    window.setTimeout(insertPixel.bind(null, eventType, previousIncTimes.join(',')), inc.time);
    return previousIncTimes;
  }, [initialPermanenceValue])
})();