ãœãªã¥ãŒã·ã§ã³ïŒ Googleã¿ã°ãããŒãžã£ãŒã䜿çšããŠãéçºè ãªãã§Googleã¢ããªãã£ã¯ã¹ã®ãããïŒãã€ããŒããµã€ãºãå«ãïŒãGoogleã¹ãã¬ããã·ãŒãã«èšé²ãã
åé¡ã®æ¬è³ª
Googleã¿ã°ãããŒãžã£ãŒïŒGTMïŒãä»ããŠGoogleã¢ããªãã£ã¯ã¹ïŒGAïŒã®æ¡åŒµeã³ããŒã¹ãå®è£ ãã Googleã¢ããªãã£ã¯ã¹ãããã¬ãŒã䜿çšããŠãã®ããžãã¹ããããã°ããããšãããå Žåã¯ãããããGAã«å°éããªãã£ãã€ãã³ããšãšã©ãŒã衚瀺ãããŸãïŒ ãã€ããŒããµã€ãºã倧ããããŸãïŒ9000ïŒã æ倧蚱容æ°ã¯8192ã§ã
ãªããããèµ·ãã£ãŠããã®ã§ããïŒ
å®éãanalytics.jsã©ã€ãã©ãªãŒã¯8192ãã€ããè¶ ããããããåãå ¥ããŸãã ã ããããµã€ãºã倧ããå ŽåãGAã«å°éãããã€ãã³ãã¬ããŒãã§ç©ºã«ãªããŸãã
ç¶æ³ã®äŸïŒ
Webã¢ããªã¹ãã¯ã1åã®ãããã§ãã¹ãŠã®è£œåã®å°è±¡ãè©°ã蟌ãïŒãŸãã¯è©°ã蟌ãïŒããã«éçºè ã«äŸé ŒããŸãã ãã®çµæããããã¯å°éããŸãã 1ããŒãžã®ãªã¹ãã«50以äžã®è£œåããããŸãã ãŸãã¯ã50以äžã®ç°ãªã補åããã¹ã±ããã«è¿œå ãããŸãããã®çµæããã§ãã¯ã¢ãŠãæé ãšãã©ã³ã¶ã¯ã·ã§ã³ã€ãã³ãã«åé¡ããããŸãã
ã©ããã
ãããããŒã¿ã®æ§é ãåžžã«æé©åããïŒã€ãŸãã補åããŠãŒã¶ãŒã®èŠéã«è¡šç€ºããããšãã«ããããéä¿¡ãããäžèŠãªå€æ°ïŒããªã¢ã³ããã«ããŽãªããã©ã³ãïŒããããã«ããã·ã¥ããªããé·ã補ååã䜿çšããªããªã©ïŒ-ããã«ããããŸãããããã®éä¿¡é床ãåäžããŸãã 次ã«ããã€ããŒããµã€ãºã®åé¡ãåé¿ããŸãã
æé©åãäžå¯èœãªå Žåããããã®å¶éãåé¿ããæ¹æ³ãããã€ããããŸãã
- customTaskã®åé¡ã«å¯ŸããçŸãã解決çã 8192æªæºã«ãªããŸã§ããã€ããŒãããäžèŠãªãã©ã¡ãŒã¿ãŒã1ã€ãã€åé€ããŸããæ£ç¢ºã«äœãã¹ããŒã§ããã-æ§æã§ããŸãã
- ããããããã€ãã®éšåã«åãåããŠåå²ããŠéä¿¡ããŸãã
- GAããŒã¿ã®ã€ã³ããŒãïŒè£œåIDã®ã¿ããããã«ããã·ã¥ããæ®ãã¯ããŒã¿ã€ã³ããŒããä»ããŠããŒã¿ããŒã¹ãšããŠããŒããããŸãïŒã
è¡åã®æºå
ãããã®ã«ãããšã³ã³ãã³ãã®æé©åãéå§ããåã«ããã€ããŒããµã€ãºãè¶ ããã€ãã³ããç¹å®ããŸãã
ã¹ããã1. Googleã¹ãã¬ããã·ãŒããèšå®ãã
æ°ããããŒãã«ãäœæããŸãã
ããããŒïŒ1è¡ïŒã«ããããããæœåºãããã©ã¡ãŒã¿ãŒã®ååãèšè¿°ããŸãïŒæå®ããååã¯ãGTMã®JSã¹ã¯ãªããã§äœ¿çšããååãšãŸã£ããåãã§ããããšã«æ³šæããŠãã ããïŒã äŸãšããŠã次ã®ããŒã¿ãæœåºããŸãã
- ã¿ã€ã ã¹ã¿ã³ã
- payLoadLength
- tidïŒè¿œè·¡IDïŒ
- cidïŒã¯ã©ã€ã¢ã³ãIDïŒ
- uidïŒãŠãŒã¶ãŒIDïŒ
- tïŒãããã®ã¿ã€ãïŒ
- païŒè£œåã¢ã¯ã·ã§ã³ïŒ
- niïŒéçžäºäœçšïŒ
- dlïŒããã¥ã¡ã³ãã®å ŽæïŒ
- dpïŒããã¥ã¡ã³ããã¹ïŒ
- dtïŒããã¥ã¡ã³ãã®ã¿ã€ãã«ïŒ
- ecïŒã€ãã³ãã«ããŽãªïŒ
- eaïŒã€ãã³ãã¢ã¯ã·ã§ã³ïŒ
- elïŒã€ãã³ãã©ãã«ïŒ
- tiïŒãã©ã³ã¶ã¯ã·ã§ã³IDïŒ
- trïŒååŒåçïŒ
Googleã·ãŒãã§ã®ãã€ããŒããã®ã³ã°ã®åãããã³ã°ã®äŸ
åå ã®ãã©ã¡ãŒã¿ãŒã®é åºã¯éèŠã§ã¯ãããŸããïŒã¿ã€ã ã¹ã¿ã³ããé€ã-æåã«ããå¿ èŠããããŸãïŒã èªåãã©ãŒãããã®ãšã©ãŒãåé¿ããããã«ãcidããã³tiãã©ã¡ãŒã¿ã䜿çšããŠåããã¬ãŒã³ããã¹ã ïŒãã©ãŒããã>æ°å€>ãã¬ãŒã³ããã¹ãïŒã§ãã©ãŒãããããŸãã
å¿ èŠã«å¿ããŠãå¿ èŠãªãã©ã¡ãŒã¿ãŒãè¿œå /åé€ã§ããŸãïŒGTMã®JSã¹ã¯ãªããå ã®å€æ°ã®ãªã¹ããå¿ããã«å€æŽããŠãã ããïŒã å¯èœãªãã£ãŒã«ããšãã©ã¡ãŒã¿ãŒã®ãªã¹ãanalytics.js
次ã«ãã¹ã¯ãªãããšãã£ã¿ãŒãéããŠã³ãŒããè¿œå ããŸãïŒå ã®ã¹ã¯ãªããã¯Martin Hawksey https://gist.github.com/mhawksey/1276293ã«å±ããŸã ïŒã
function doGet(e){ return handleResponse(e); } function doPost(e){ return handleResponse(e); } function handleResponse(e) { var lock = LockService.getPublicLock(); lock.waitLock(30000); // wait 30 seconds before conceding defeat. try { // next set where we write the data - you could write to multiple/alternate destinations var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // we'll assume header is in row 1 but you can override with header_row in GET/POST data var headRow = e.parameter.header_row || 1; var headers = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues()[0]; var nextRow = sheet.getLastRow()+1; // get next row var row = []; // loop through the header columns for (i in headers){ if (headers[i] == "timestamp"){ // special case if you include a 'timestamp' column row.push(Utilities.formatDate(new Date(), Session.getScriptTimeZone(), "MMM d yyyy HH:mm:ss")); } else { // else use header name to get data row.push(e.parameter[headers[i]]); } } // more efficient to set values as [][] array than individually sheet.getRange(nextRow, 1, 1, row.length).setValues([row]); // return json success results return ContentService .createTextOutput(JSON.stringify({"result":"success", "row": nextRow})) .setMimeType(ContentService.MimeType.JSON); } catch(e){ // if error return this return ContentService .createTextOutput(JSON.stringify({"result":"error", "error": e})) .setMimeType(ContentService.MimeType.JSON); } finally { //release lock lock.releaseLock(); } }
ã¹ã¯ãªãããWebã¢ããªã±ãŒã·ã§ã³ãšããŠå±éããŸãïŒ[å ¬é]> [Webã¢ããªãšããŠå±é...]ïŒã æš©é-誰ã§ããå¿åã§ãã ãããªãã·ã¥ã
Google Scriptãšãã£ã¿ãŒã®èšå®
å°æ¥ãWebã¢ããªã±ãŒã·ã§ã³ã®URLïŒçŸåšã®Webã¢ããªã®URLïŒãå¿ èŠã«ãªãããããŸã ã¿ããéããªãã§ãã ããã
ã¹ããã2. GTMãæ§æãã
2ã€ã®ã«ã¹ã¿ã JavaScriptå€æ°ãäœæããŸãã
- v_EE_timestamp
- v_EE_mimic GAãã€ããŒã
GTM JavaScriptå€æ°ã®äŸ
ããããéä¿¡ãããæå»ïŒã¿ã€ã ã¹ã¿ã³ãïŒã決å®ããæåã®JSå€æ° ã ãã®å€æ°ã¯ã2çªç®ã®JSå€æ°ã§äœ¿çšãããŸãã
function() { // Get local time as ISO string with offset at the end var now = new Date(); var tzo = -now.getTimezoneOffset(); var dif = tzo >= 0 ? ' Timezone: +' : ' Timezone: -'; var pad = function(num) { var norm = Math.abs(Math.floor(num)); return (norm < 10 ? '0' : '') + norm; }; return now.getFullYear() + '-' + pad(now.getMonth()+1) + '-' + pad(now.getDate()) + ' Time' + pad(now.getHours()) + ':' + pad(now.getMinutes()) + ':' + pad(now.getSeconds()) + dif + pad(tzo / 60) + ':' + pad(tzo % 60); }
2çªç®ã®JSå€æ° ãå¿ èŠãªãããããã£ããããŠGoogleã·ãŒãã«è»¢éããããïŒ ãã®è³æã®ã³ãŒãã«åºã¥ããŠïŒã
function sendHitTask(){ return function(model) { var payLoad = model.get('hitPayload'); var trackingBaseUrls = ['https://www.google-analytics.com/collect', 'https://script.google.com/macros/s/AKfycbxJLy3eYBLpPu_S_eNccxzn_GwHXkZWr-93feMuBaAZelk3fj01yB/exec']; for (i = 0; i < trackingBaseUrls.length; i++) { var baseUrl = trackingBaseUrls[i]; if (trackingBaseUrls[i].indexOf('collect') > -1) { var req = new XMLHttpRequest(); req.open('POST', baseUrl, true); req.send(payLoad); } else if (payLoad.length > 7500){ var payLoadExtract = payLoad.split('&'); var payLoadArray = {}; // Push values to array for later access for (i = 0; i < payLoadExtract.length; i++){ var splitArray = payLoadExtract[i].split('='); payLoadArray[splitArray[0].trim()] = splitArray[1].trim(); } // Specify values to be sent to Google Sheets from array var tid = 'tid=' + payLoadArray.tid, cid = '&cid=' + payLoadArray.cid, uid = '&uid=' + payLoadArray.uid, t = '&t=' + payLoadArray.t, pa = '&pa=' + payLoadArray.pa, ni = '&ni=' + payLoadArray.ni, dl = '&dl=' + payLoadArray.dl, dp = '&dp=' + payLoadArray.dp, dt = '&dt=' + payLoadArray.dt, ec = '&ec=' + payLoadArray.ec, ea = '&ea=' + payLoadArray.ea, el = '&el=' + payLoadArray.el, ti = '&ti=' + payLoadArray.ti, tr = '&tr=' + payLoadArray.tr, timestamp = '×tamp=' + {{v_EE_timestamp}}, payLoadLength = '&payLoadLength=' + payLoad.length; var collectPayLoad = tid + cid + uid + t + pa + ni + dl + dp + dt + ec + ea + el + ti + tr + timestamp + payLoadLength; // Send Values to Google Sheets var collectUrl = baseUrl +'?'+ collectPayLoad; var myImage = new Image(); myImage.src = collectUrl; } } } }
èšå®ããå¿ èŠããããã®ïŒ
- trackingBaseUrlså€æ°ã«ãWebã¢ããªã±ãŒã·ã§ã³ã®URLïŒæé 1ã§äœæïŒããã³google analyticsã®URLãæ¿å ¥ããŸãã
- payLoad.lengthã§ããã£ãããããããã®ãµã€ãºã決å®ããŸãã äŸã§ã¯ãset> 7500ãã€ãŸã 8192ãã€ãã®ãããå€ãæœåšçã«è¶ ããå¯èœæ§ã®ãããã¹ãŠããã£ããããŸãã ãã°å šäœãèå³æ·±ãå Žåã¯ãè³ãéãæžããããšãã§ããŸãã
- Req.openã¯ãããããéä¿¡ããããã®ã¡ãœãããå®çŸ©ããŸãïŒãããã®ãµã€ãºã«å¿ããŠãPOSTãŸãã¯GETã«ãªããŸããGoogle㯠ããã倧ããªãã€ããŒããéä¿¡ã§ããããã POSTã䜿çšããããšããå§ãããŸãïŒã ããã©ã«ãã§ã¯ãGAã®ã€ãã³ãã¯GETãä»ããŠéä¿¡ãããŸãã æ¡åŒµeã³ããŒã¹ã®å Žåã¯ãéä¿¡æ¹æ³ãPOSTã«å€æŽããããšããå§ãããŸãïŒFieldsã®Enhance ecommerceã¿ã°ã«è¿œå ããŠèšå®ããŸãïŒ transport-beakon ïŒ
次ã«ãã³ã³ããå ã§æ¡åŒµeã³ããŒã¹ã€ãã³ããGAã«éä¿¡ããã¿ã°ãèŠã€ãã察å¿ããããªã¬ãŒãåç §ããŠãããã®ã³ããŒãäœæããŸãã
ã¿ã°ã®ã³ããŒã§ãGA IDãanyïŒtest / fakeïŒã«å€æŽãã sendHitTaskãã£ãŒã«ããšååJSå€æ°ïŒv_EE_mimic GAãã€ããŒãïŒã[èšå®ãããã£ãŒã«ã]ã«è¿œå ããŸãã
ãã®å ŽåãsendHitTaskã¯å€æŽãããŸãã ãããããŒã¿ããã¹ãGAã«éä¿¡ããŸãïŒéä¿¡ããããšã¯ã§ããŸããããã®ãããã³ãŒãå ã®å€'https://www.google-analytics.com/collect'ãåé€ããŸãïŒããã³Googleã·ãŒãïŒæå®ããããã€ããŒããµã€ãºãè¶ ããå ŽåïŒã
å ã®æ¡åŒµeã³ããŒã¹ã¿ã°ã«è§Šããªãããã«ããã¹ãGA IDã®ã¿ã°ã®ã³ããŒãä¿éºã«å¿ èŠã§ãã å ã®ã¿ã°ã®sendHitTaskãïŒã³ããŒãäœæããã«ïŒå€æŽã§ããŸãããcustomTaskã䜿çšããããšã¯ã§ããŸããïŒsendHitTaskãçµ±åããããšã§å€æŽããå¿ èŠããããŸãïŒãå®å šã«ããŸãïŒã
GTMæ¡åŒµeã³ããŒã¹ã¿ã°èšå®
ã¿ã°ãä¿åããGTMã³ã³ããã®æ°ããããŒãžã§ã³ãå ¬éããŸãã
ãŸãšã
çŸåšãEnhance ecommerceã¿ã°ãããªã¬ãŒããããšãv_EE_mimic GAãã€ããŒãã¹ã¯ãªãããæ©èœããŸãã æå®ãããèšå®ã§ãã€ããŒãããã®å€ãè¶ ãããšããã®ãããã¯Googleã·ãŒãã«èšé²ãããŸãã
ãããããšã«ãã°ãåéããããšã«ãããã©ã®ç¹å®ã®ã€ãã³ããGAã«å°éããªãã£ãããã©ãã§çºçããããã©ã®ãã©ãŠã¶ãªã©ã§ç¹å®ã§ããŸãã ïŒ å¯èœãªãã£ãŒã«ããšãã©ã¡ãŒã¿ãŒã®ãªã¹ãanalytics.jsãåç §ããŠãã ããïŒã
ãæž èŽããããšãããããŸããïŒ
ãã®è³æã圹ã«ç«ã¡ãGoogleã¢ããªãã£ã¯ã¹ã®ãããã°ã楜ã«ãªãããšãé¡ã£ãŠããŸãã
PS GTMã¿ã°ã®æ€èšŒãèªååããæ¹æ³ïŒã¿ã°ã®èªåãã¹ãïŒãç¥ã£ãŠãã人ã¯ãè¿ä¿¡ããŠãã ããïŒ ãããããããSimoã¯ããã«ã€ããŠã®èšäºãwww.simoahava.com/analytics/automated-tests-for-google-tag-managers-datalayerã«æžããŸããããç解ã§ããŸããã§ããããã¶ã誰ããä»ã®æ¹æ³ãè©Šãã/ç¥ã£ãŠããŸãã ç§ã¯ãã®åé¡ã«ã€ããŠã¢ããã€ã¹ãšå©ããéåžžã«æè¬ããŸãã