
;(function(){
  'use strict';
  try {
    var query = window.location.search;
    if (query.length === 0) {
        return;
    }

    var adtrackXhr = new XMLHttpRequest();
    adtrackXhr.open('GET', 'https://adtrack.unext.jp/api/1/adtrack' + query, true);
    adtrackXhr.withCredentials = true;
    adtrackXhr.send(null);

    var json = {};
    query.substring(1).split('&').forEach(function(pair) {
      var [key, value] = pair.split('=');
      json[decodeURIComponent(key)] = decodeURIComponent(value || '');
    });

    var trackSetXhr = new XMLHttpRequest();
    trackSetXhr.open('POST', 'https://sidecar.unext.jp/track/set', true);
    trackSetXhr.withCredentials = true;
    trackSetXhr.setRequestHeader('Content-Type', 'application/json');
    trackSetXhr.send(JSON.stringify(json));
  } catch (error) {
    console.error('Error occurred:', error);
  }
}());