[JavaScript][GA] Google analytics – 兩組帳號、多帳號並存一網站 (通用分析)

看以下Code即可: <script> (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’,’//www.google-analytics.com/analytics.js’,’ga’); ga(‘create’, ‘UA-12345678-1’, ‘auto’); //建立第一個帳號 ga(‘create’, ‘UA-87654321-2’, ‘auto’, ‘secondGA’}); //建立第二個帳號 ga(‘require’, ‘displayfeatures’); //啟用客層和興趣報表 ga(‘send’, ‘pageview’); //送出第一個帳號PV ga(‘secondGA.send’,’pageview’); //送出第二個帳號PV </script> Refer:https://developers.google.com/analytics/devguides/collection/analyticsjs/creating-trackers

[jQuery] AJAX跨網域 | AJAX Cross Domain Request withCredentials (Access-Control-Allow-Origin)

做個AJAX跨網域可是容易忘記細節的,這就來篇Note, 後端部分,Server Header請開啟(以PHP動態Header為例): header(“Access-Control-Allow-Origin: *”); header(“Access-Control-Allow-Credentials: true”); Cookie夾帶 如需夾帶Cookie則前端的AJAX需開啟Credentials,JQuery為例: $.ajax({ xhrFields: { withCredentials: true }, type: “GET”, url: “http://www.example.org/ajax.php” }).done(function (data) { console.log(data); }); xhrFields中withCredentials要開啟,這就是亮點!

[JS][jQuery] AJAX Cross Domain Request | AJAX跨網域應用

做個AJAX跨網域可是容易忘記細節的,這就來篇Note, 後端部分,Server Header請開啟(以PHP動態Header為例): header(“Access-Control-Allow-Origin: *”); header(“Access-Control-Allow-Credentials: true”); 重點是前端的AJAX呀,JQuery為例: $.ajax({ xhrFields: { withCredentials: true }, type: “GET”, url: “http://www.example.org/ajax.php” }).done(function (data) { console.log(data); }); xhrFields中withCredentials要開啟,這就是亮點!