Created
August 9, 2019 12:15
-
-
Save ideacco/d03e69f392bd2fe2ce296e86f8a1573a to your computer and use it in GitHub Desktop.
shopify 按钮修改
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//原始网站区域 | |
(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-104793185-3', 'auto'); | |
ga('send', 'pageview'); | |
// shopify 的代码区域 | |
// 备选方案2 | |
// 自定义正则方法获取URL的地址段,提取gid | |
function getClientIdFromUrl() { | |
var url = window.location.href; | |
var regex = new RegExp("[#&]_ga(=([^&#]*)|&|#|$)"), | |
results = regex.exec(url); | |
if (!results) return null; | |
if (!results[2]) return ''; | |
return decodeURIComponent(results[2].replace(/\+/g, " ")); | |
} | |
ga('create', 'UA-104793185-3', 'auto', { | |
'clientId': getClientIdFromUrl() | |
}); | |
ga('create', 'UA-104793185-3', 'auto', { | |
'clientId': '52518855.1565093909' | |
}); | |
ga(function(tracker) { | |
alert(tracker.get('linkerParam')); | |
}); | |
var url = 'https://go2sleep-official.myshopify.com/8599306317/checkouts/2026e30899116d12ae512acbd4376656#_ga=1.2.573623456.1564730895' | |
var regex = new RegExp("[#&]_ga(=([^&#]*)|&|#|$)"),results = regex.exec(url); | |
console.log(results) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment