Skip to content

Instantly share code, notes, and snippets.

@fergusKe
Last active March 23, 2022 09:55
Show Gist options
  • Save fergusKe/5324de8dd19cf3807a2ccc651e5816b8 to your computer and use it in GitHub Desktop.
Save fergusKe/5324de8dd19cf3807a2ccc651e5816b8 to your computer and use it in GitHub Desktop.
(function($) {
var eventCategoryString = '會員註冊';
$('#email').on('change', function() {
pushDatalayer('填寫資料 - E-mail', $(this).val());
});
$('#passwd1').on('change', function() {
pushDatalayer('填寫資料 - 輸入密碼', '次數');
});
$('#passwd2').on('change', function() {
pushDatalayer('填寫資料 - 輸入確認密碼', '次數');
});
$('#name').on('change', function() {
pushDatalayer('填寫資料 - 輸入姓名', $(this).val());
});
$('#leye').on('change', function() {
pushDatalayer('填寫資料 - 選取左眼度數', $(this).val());
});
$('#reye').on('change', function() {
pushDatalayer('填寫資料 - 選取右眼度數', $(this).val());
});
// select
// $('#brandselect').change(function() {
// var label = $(this).find('option:selected').text();
// });
// radio
$('input[name=gender]').on('change', function() {
pushDatalayer('填寫資料 - 選取性別', $('input[name="gender"]:checked').val() == 'M' ? '男' : '女');
});
// 年月日
$('#year, #month, #day').on('change', function() {
var year = $('#year').val();
var month = $('#month').val();
var day = $('#day').val();
if (year === '' || month === '' || day === '') return;
pushDatalayer('填寫資料 - 選取生日', year + '/' + month + '/' + day);
});
// $('#year, #month, #day').on('change', function() {
// pushDatalayer('填寫資料 - 選取生日', $('#year').val() + '/' + $('#month').val() + '/' + $('#day').val());
// });
$('#cellphone').on('change', function() {
pushDatalayer('填寫資料 - 輸入手機號碼', $(this).val());
});
// checkbox
$('#edm').on('change', function() {
pushDatalayer('填寫資料 - 勾選同意收到電子報', $(this).prop("checked") ? '同意電子報' : '不同意電子報');
});
$('#note').on('change', function() {
pushDatalayer('填寫資料 - 勾選同意注意事項', $(this).prop("checked") ? '同意注意事項' : '不同意注意事項');
});
$('#rg_button').on('click', function() {
pushDatalayer('註冊新會員', '確認');
});
// 檢查表單是否有填寫
$('.btn-default').on('click', function() {
var itemArr = ['#user_email', '#user_password', '#user_password_confirmation', '#user_name', '#user_mobile'];
var isHaveVal = true;
itemArr.forEach(function(item) {
if($(item).val() == "") {
isHaveVal = false;
}
})
if (isHaveVal) {
pushDatalayer('確定註冊', '成功');
} else {
pushDatalayer('確定註冊', '失敗');
}
});
function pushDatalayer(thisAction, thisLabel) {
dataLayer.push({
event: 'cusevent',
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