Skip to content

Instantly share code, notes, and snippets.

@fergusKe
Created November 15, 2018 08:04
Show Gist options
  • Save fergusKe/a3052d263e3d81cb770b9fcd2774346e to your computer and use it in GitHub Desktop.
Save fergusKe/a3052d263e3d81cb770b9fcd2774346e to your computer and use it in GitHub Desktop.
(function($) {
var dataLayer = window.dataLayer || [];
var eventString = 'cusevent';
var eventCategoryString = '會員註冊';
$('#rg_button').click(function(e) {
var eventInfo = [
['填寫資料 - E-mail', $('#email').val()],
['填寫資料 - 輸入密碼', $('#passwd1').val()],
['填寫資料 - 輸入確認密碼', $('#passwd2').val()],
['填寫資料 - 選取左眼度數', $('#leye').val()],
['填寫資料 - 選取右眼度數', $('#reye').val()],
['填寫資料 - 選取性別', $('input[name=gender]:checked').val() == 'M' ? '男' : '女'],
['填寫資料 - 選取生日', $('#year').val() + '/' + $('#month').val() + '/' + $('#day').val()],
['填寫資料 - 輸入手機號碼', $('#cellphone').val()],
['填寫資料 - 勾選同意收到電子報', $('#edm').prop("checked") ? '同意電子報' : '不同意電子報'],
['填寫資料 - 勾選同意注意事項', $('#note').prop("checked") ? '同意注意事項' : '不同意注意事項'],
['註冊新會員', '確認'],
];
for ( var k2 in eventInfo ){
pushDatalayer(eventInfo[k2][0], eventInfo[k2][1]);
}
});
function pushDatalayer(thisAction, thisLabel) {
// console.log('thisAction = ', thisAction + ' thisLabel = ', thisLabel);
dataLayer.push({
event: eventString,
eventCategory: eventCategoryString,
eventAction: thisAction,
eventLabel: thisLabel
});
}
})(jQuery)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment