// Copyright 2018 Y's creative factory All rights reserved. /********** * 「Google アナリティクス トラッキング Measurement Protocol」を参考に決定 * https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters * * v : プロトコルバージョン(v) 今のところ「1」 * t : ヒットタイプ(t) 今のところ「pageview」のみ * dl : ドキュメントのURL(dl) * ul : ユーザ言語(ul) * de : ドキュメントエンコード(de) * dt : ドキュメントのタイトル(dt) * cid : クライアントID(cid) * tid : トラッキングID(tid) * dr : リファラー * sr : ディスプレイサイズ * vp : 表示サイズ * z : キャッシュ防止用(z) **********/ if (!Object.assign) { Object.defineProperty(Object, 'assign', { enumerable: false, configurable: true, writable: true, value: function(target) { 'use strict'; if (target === undefined || target === null) { throw new TypeError('Cannot convert first argument to object'); } var to = Object(target); for (var i = 1; i < arguments.length; i++) { var nextSource = arguments[i]; if (nextSource === undefined || nextSource === null) { continue; } nextSource = Object(nextSource); var keysArray = Object.keys(Object(nextSource)); for (var nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex++) { var nextKey = keysArray[nextIndex]; var desc = Object.getOwnPropertyDescriptor(nextSource, nextKey); if (desc !== undefined && desc.enumerable) { to[nextKey] = nextSource[nextKey]; } } } return to; } }); } window.addEventListener('load', function() { var $_image_src = "https://www.ycfma.com/collect", $_popup_url = "https://www.ycfma.com/popup", $_date = new Date(), $_data = { 'resource' : { 'v' : '1', 't' : 'pageview', 'dl' : location.href, 'ul' : window.navigator.userLanguage || window.navigator.language || window.navigator.browserLanguage, 'de' : document.charset, 'dt' : document.title, 'cid' : '', 'tid' : 'MA-000000072-81', 'dr' : document.referrer, 'sr' : (window.parent.screen.width + 'x' + window.parent.screen.height), 'vp' : (window.innerWidth + 'x' + window.innerHeight), 'z' : Math.floor($_date.getTime() / 1000) } }; function getType(obj){ if (typeof obj === "undefined") { // objがundefined return "undefined"; } else if (obj === null) { // objがnull return "null"; } else { // objが有効 // prototype名取得 var className = Object.prototype.toString.call(obj); // "object"以降のクラス名を取得 var matches = className.match(/^\[object\s(.*)\]$/); if (matches.length > 0) { // クラス名が存在 return matches[1]; } else { return className; } } }; function extend(){ var i = 1, key, length = arguments.length, // 引数がなければ空のオブジェクトを返す target = arguments[0] || {}, isDeep = false; // 第1引数がtrueだったときディープコピー if (target === true) { ++i; target = arguments[1] || {}; isDeep = true; } // 引数の数だけループ // 第1引数は除く(ディープコピーの場合は第2引数も) for (; i < length; ++i) { for (key in arguments[i]) { if (arguments[i].hasOwnProperty(key)) { // ディープコピーの場合は再帰呼び出し if (isDeep && Object.prototype.toString.call(arguments[i][key]) === '[object Object]') { target[key] = extend(target[key], arguments[i][key]); } else { target[key] = arguments[i][key]; } } } } return target; }; function objectToQueryString(obj){ if(!Object.keys){ Object.keys = function(obj){ var keys = []; for(var i in obj){ if(obj.hasOwnProperty(i)){ keys.push(i); } } return keys; }; } return Object.keys(obj) .filter(function(key){return obj[key] !== '' && obj[key] !== null}) .map(function(key, index){ var startWith = index === 0 ? '?' : '&'; return startWith + encodeURIComponent(key) + '=' + encodeURIComponent(obj[key]) } ).join(''); } function uniqueID(){ var randam = Math.floor(Math.random()*1000) var date = new Date(); var time = date.getTime(); return randam + time.toString(); } /*function objectToQueryString(value, sep, eq, isEncode){ sep = sep || '&'; // 省略時は & eq = eq || '='; // 省略時は = // エンコードするかどうか var encode = (isEncode) ? encodeURIComponent : function(a) { return a; }; // Object.keys で key 配列を取得し, それを map で回した結果を sep(&) で join して返す return Object.keys(value).map(function(key) { // key, value を eq(=) で連結した文字列を返す return key + eq + encode(value[key]); }).join(sep); }*/ function getCookieArray(){ var arr = new Array(); if(document.cookie != ''){ var tmp = document.cookie.split('; '); for(var i=0;i 0){ elem.getElementsByClassName('popupFormBoxClose')[0].addEventListener('click',function handleSelected(event){ elem.classList.remove('slidein'); elem.classList.add('fadeout'); setTimeout(function(){ // elem.style.display = "none"; },500); },false); elem.getElementsByClassName('popupFormBoxOpen')[0].addEventListener('click',function handleSelected(event){ elem.classList.remove('fadeout'); elem.classList.add('slidein'); setTimeout(function(){ // elem.style.display = "unset"; },500); },false); } //フォームにIDを追加 var $_uniqueid = uniqueID(); elem.getElementsByClassName('popupFormBox')[0].setAttribute('id',$_uniqueid); //クライアントID $_input_client.type = 'hidden'; $_input_client.name = 'cid'; $_input_client.value = $_cookies['_ma']; document.getElementById($_uniqueid).appendChild($_input_client); //セッションID $_input_session.type = 'hidden'; $_input_session.name = 'cs'; $_input_session.value = $_cookies['_mid']; document.getElementById($_uniqueid).appendChild($_input_session); //送信処理 function send_data($_formid){ // XMLHttpRequest オブジェクトを作成 var $_XHR = new XMLHttpRequest(); // form 要素にアクセス var $_target_form = document.getElementById($_formid); // FormData オブジェクトを作成し、form 要素を紐づける var $_FD = new FormData($_target_form); // 送信完了時 $_XHR.addEventListener('load', function(event){ console.log('送信完了'); }); // ネットワークエラー時 $_XHR.addEventListener("error", function(event){ console.log('ネットワークエラー'); }); // リクエストをセットアップ var $_method = document.getElementById($_uniqueid).getAttribute('method'); var $_action = document.getElementById($_uniqueid).getAttribute('action'); $_XHR.open($_method,$_action,true); // 送信 $_XHR.send($_FD); // 返り値をチェック $_XHR.onreadystatechange = function(){ if (($_XHR.readyState == 4) && ($_XHR.status == 200)) { console.log($_XHR.responseText); var $_response = JSON.parse($_XHR.responseText); if($_response.result == 'success'){ $response_html = $_response.html; $response_html = $response_html.replace(/\r\n/g, '
'); let html = '
×
'; html += '
' + $response_html + '
'; if($_response.attachment ==true && $_response.popup_id !=null){ html += '

'; html +=''; } elem.getElementsByClassName('ma__creative_container_innerbox')[0].innerHTML = html }else{ elem.insertAdjacentHTML('afterbegin','

送信時にエラーが発生しました。再度お試しください。

'); } } }; } document.getElementById($_uniqueid).submitbtn.addEventListener('click',function(){ var $_form = document.getElementById($_uniqueid), $_error = 0, $_elements = $_form.querySelectorAll('.popupFormControls'); console.log($_elements); for(var $_i = 0;$_i < $_elements.length;$_i++){ var $_type = $_elements[$_i].type, $_validationMessage = $_elements[$_i].validationMessage; console.log($_validationMessage); if($_validationMessage != ''){ $_elements[$_i].parentNode.setAttribute('data-errormessage',$_validationMessage); $_elements[$_i].parentNode.classList.add('error'); $_error++; }else{ $_elements[$_i].parentNode.removeAttribute('data-errormessage'); $_elements[$_i].parentNode.classList.remove('error'); } } if(!$_error){ send_data($_uniqueid); } },false); } } } xmlhttp2.open("GET",$_url,true); xmlhttp2.send(null); } function dataPost(){ var $_dataLayer = window.dataLayer || [], $_image = new Image(), $_src = $_image_src, $_resource = $_data.resource, $_cookies = getCookieArray(), $_uid = '', $_cs = '', $_list = document.getElementsByClassName('ma__creative_container'); //ユーザーを区別用(2年有効) if(!$_cookies['_ma']){ if(('localStorage' in window) && (window.localStorage !== null)) { if(window.localStorage.getItem('_ma')){ $_uid = window.localStorage.getItem('_ma'); }else{ $_uid = 'MA' + $_resource.v + '.' + Math.random() + '.' + $_resource.z; window.localStorage.setItem('_ma',$_uid); } } setCookie('_ma',$_uid,730); }else{ $_uid = $_cookies['_ma']; setCookie('_ma',$_uid,730); } $_resource.cid = $_uid; //ユーザーをセッション区別(30分有効) if(!$_cookies['_mid']){ $_cs = 'MA' + $_resource.v + '.' + Math.random() + '.' + $_resource.z; setCookie('_mid',$_cs,0.020833); }else{ $_cs = $_cookies['_mid']; setCookie('_mid',$_cs,0.020833); } $_resource.cs = $_cs; //送信データ加工 if($_dataLayer.length){ $_dataLayer.forEach(function($_arguments){ if($_arguments[0] && $_arguments[1] && getType($_arguments[0]) == 'String' && getType($_arguments[1]) == 'String'){ var $_arguments00 = $_arguments[0], $_arguments01 = $_arguments[1], $_tmp = {}; $_tmp[$_arguments00] = $_arguments01; $_resource = Object.assign($_resource,$_tmp); } }); } // request tracking $_src += objectToQueryString($_resource); $_image.src = $_src; if($_list.length){ for($_i = 0;$_i < $_list.length; ++$_i) { var $_tid = $_list[$_i].getAttribute('data-tid'), $_popupid = $_list[$_i].getAttribute('data-popupid'); if($_tid == $_resource.tid){ var $_uniqueid = uniqueID(); $_list[$_i].setAttribute('id',$_uniqueid); HTML_Load($_popup_url+'?tid='+$_resource.tid+'&cid='+$_uid+'&popupid='+$_popupid,$_uniqueid); } } } }; dataPost(); }); function closePopup(){ document.querySelector(".ma__creative_container").remove() } function downloadAttachment(popup_id){ const form = document.createElement('form'); action = "https://www.ycfma.com/attachment/:id"; action = action.replace(':id',popup_id); form.method = 'get'; form.action = action; document.body.appendChild(form); form.submit(); form.remove(); }