/**
* 使い方:
*
* → 読み込むだけで、ページ表示完了後に自動で記録処理が実行される
*/
(function (root, factory) {
if (typeof module === 'object' && module.exports) {
module.exports = factory(); // CommonJS
} else if (typeof define === 'function' && define.amd) {
define(factory); // AMD
} else {
root.JcInboundTracker = factory(); // グローバル変数
}
}(typeof self !== 'undefined' ? self : this, function () {
'use strict';
var ENDPOINT = '/jcapi/_jc_ibltrack.php';
var UTM_KEYS = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content'];
function collectUtmParams() {
var params = new URLSearchParams(location.search);
var result = {};
UTM_KEYS.forEach(function (key) {
result[key] = params.get(key) || null;
});
return result;
}
function buildPayload() {
return {
referrer: document.referrer || null,
landing_url: location.href,
landing_path: location.pathname,
query_string: location.search ? location.search.substring(1) : null,
utm: collectUtmParams(),
user_agent: navigator.userAgent
};
}
/**
* 記録リクエストを送信する
* @returns {Promise