顯示具有 img 標籤的文章。 顯示所有文章
顯示具有 img 標籤的文章。 顯示所有文章

2015年10月27日 星期二

透過 Google Analytics - Measurement Protocol 追蹤 IOT、Email 開信率等

雖然很多東西都建立在 Android 上,但總是有純 Unix 的環境,這時就用用 Google analytics (GA) 的 REST API 了 XD 這東西用途很廣,因為它可以偽裝成 image ,例如 <img src="//www.google-analytics.com/collect?...">,甚至可以用在 EDM 等等的(雖然 Email 常常預設把遠端資源關閉) ,此例,我們專注在 IOT 上,而測試方式只要用用 cURL 即可,十分便利。

由於是 IOT 角色,須留意 GA 的資源限制:https://developers.google.com/analytics/devguides/collection/protocol/v1/limits-quotas

  • 10 million hits per month per tracking ID
  • 200,000 hits per user per day
  • 500 hits per session not including ecommerce (item and transaction hit types).

總之,用法都很簡單,叫 IOT 定期打卡即可,最重要的工作項目反而是定義產品的使用情境,把那些狀態定義好後,當作 web page 來呼叫 Google Analytics API 吧!

簡易範例:

$ curl 'https://www.google-analytics.com/collect?v=1&t=screenview&tid=TRACKING_ID&an=YOUR_APP_NAME&cid=CLIENT_ID&cd=YOUR_PRODUCT_STATE'
GIF89a?????


其中範例回應的就是一張 GIF 圖檔,而更多應用請參考 https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters ,若一直試不出來,可以用 https://ga-dev-tools.appspot.com/hit-builder/ 偵錯看看。

2014年3月11日 星期二

[Javascript] AngularJS 與 img src & img ng-src

用 AngularJS 在處理 img 時,沒看手冊的用法:

<img src="{{item.url}}" />

雖然網頁顯示一切正常,但仔細看 Google Chrome 開發人員工具時,發現有奇怪的 requests 發出去,是的,發出去的資料就是 http://hostname/%7B%7Bitem.url%7D%7D ,解法就是改用 ng-src 吧!

<img ng-src="{{item.url}}" />

AngularJS 官方文件 ngSrc :

Using Angular markup like {{hash}} in a src attribute doesn't work right: The browser will fetch from the URL with the literal text {{hash}} until Angular replaces the expression inside {{hash}}. The ngSrc directive solves this problem.