0
所以我上週工作,我沒有改變任何代碼或任何東西。jQuery與谷歌分析href
我有谷歌分析JavaScript文件正在加載.htaccess文件,以便它始終用於所有頁面等等。上週我測試函數時工作得很好。
突然之間,只有最後一個「else if」函數工作,它是/ cart /的url。對我沒有意義。
在你問之前,我使用jquery而不是$,因爲默認情況下,jquery沒有加載/所以$給出錯誤。
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-xxxxxxx-1', 'auto');
ga('send', 'pageview');
// requires jQuery
+function (ga){
jQuery(document).ready(function() {
if(window.location.href.indexOf("flat-model-specs/") > -1) {
ga('send', 'event', {
'eventCategory': 'Models',
'eventAction': 'click',
'eventLabel': 'Flat Model Specs',
'transport': 'beacon'
});
}
if(window.location.href.indexOf("utility-model-specs/") > -1) {
ga('send', 'event', {
'eventCategory': 'Models',
'eventAction': 'click',
'eventLabel': 'Utility Model Specs',
'transport': 'beacon'
});
}
else if(window.location.href.indexOf("goose-model-specs/") > -1) {
ga('send', 'event', {
'eventCategory': 'Models',
'eventAction': 'click',
'eventLabel': 'Goose Model Specs',
'transport': 'beacon'
});
}
else if(window.location.href.indexOf("enclosed-model-specs/") > -1) {
ga('send', 'event', {
'eventCategory': 'Models',
'eventAction': 'click',
'eventLabel': 'Enclosed Model Specs',
'transport': 'beacon'
});
}
else if(window.location.href.indexOf("dock-height/") > -1) {
ga('send', 'event', {
'eventCategory': 'Models',
'eventAction': 'click',
'eventLabel': 'Dock Height',
'transport': 'beacon'
});
}
else if(window.location.href.indexOf("specs/") > -1) {
ga('send', 'event', {
'eventCategory': 'Models',
'eventAction': 'click',
'eventLabel': 'Specs',
'transport': 'beacon'
});
}
else if(window.location.href.indexOf("features/") > -1) {
ga('send', 'event', {
'eventCategory': 'Features',
'eventAction': 'click',
'eventLabel': 'Features Page',
'transport': 'beacon'
});
}
else if(window.location.href.indexOf("air-or-rubber-suspension/") > -1) {
ga('send', 'event', {
'eventCategory': 'Features',
'eventAction': 'click',
'eventLabel': 'Air or Rubber Suspension Page',
'transport': 'beacon'
});
}
else if(window.location.href.indexOf("accessories/") > -1) {
ga('send', 'event', {
'eventCategory': 'Accessories',
'eventAction': 'click',
'eventLabel': 'Accessories Page',
'transport': 'beacon'
});
}
else if(window.location.href.indexOf("product/battery/") > -1) {
ga('send', 'event', {
'eventCategory': 'Product',
'eventAction': 'click',
'eventLabel': 'Battery',
'transport': 'beacon'
});
}
else if(window.location.href.indexOf("video-portfolio/") > -1) {
ga('send', 'event', {
'eventCategory': 'Videos',
'eventAction': 'click',
'eventLabel': 'Video Page',
'transport': 'beacon'
});
}
else if(window.location.href.indexOf("financing/") > -1) {
ga('send', 'event', {
'eventCategory': 'Financing',
'eventAction': 'click',
'eventLabel': 'Financing Page',
'transport': 'beacon'
});
}
else if(window.location.href.indexOf("frequently-asked-questions/") > -1) {
ga('send', 'event', {
'eventCategory': 'Resources',
'eventAction': 'click',
'eventLabel': 'FAQ Page',
'transport': 'beacon'
});
}
else if(window.location.href.indexOf("brochure/") > -1) {
ga('send', 'event', {
'eventCategory': 'Resources',
'eventAction': 'click',
'eventLabel': 'Brochure Page',
'transport': 'beacon'
});
}
else if(window.location.href.indexOf("become-a-dealer/") > -1) {
ga('send', 'event', {
'eventCategory': 'Resources',
'eventAction': 'click',
'eventLabel': 'Become a Dealer Page',
'transport': 'beacon'
});
}
else if(window.location.href.indexOf("about-us/") > -1) {
ga('send', 'event', {
'eventCategory': 'About Us',
'eventAction': 'click',
'eventLabel': 'About Us Page',
'transport': 'beacon'
});
}
else if(window.location.href.indexOf("contact-us/") > -1) {
ga('send', 'event', {
'eventCategory': 'Contact Us',
'eventAction': 'click',
'eventLabel': 'Contact Us Page',
'transport': 'beacon'
});
}
else if(window.location.href.indexOf("shop/") > -1) {
ga('send', 'event', {
'eventCategory': 'Shop',
'eventAction': 'click',
'eventLabel': 'Shopping Page',
'transport': 'beacon'
});
}
else if(window.location.href.indexOf("cart/") > -1) {
ga('send', 'event', {
'eventCategory': 'Cart',
'eventAction': 'click',
'eventLabel': 'Shopping Cart Page',
'transport': 'beacon'
});
}
});
}
(function (a,b,c){
if(a === 'send'){
window.ga('send',b,c)
}
})