2013-12-09 44 views
0

我想添加事件追蹤到正在轉換爲HTML跨域產品...附加GA事件跟蹤,以JSON元素

該文件位於服務器端和PHP編寫的。 JSON的片斷,我需要追加GA事件如下:

"products": [ 
    { 
     "title": "product", 
     "description": "description", 
     "thumbnail": "http://myurl.com/picture.jpg", 
     "price": "£1.99", 
     "url": "http://link.com" 
    },] 

現在,讀了這篇文章對這個一點給了我一些真知灼見:Using google analytics to track hits on an XML web service

難道是這樣簡單的事嗎?

<?php 
//Initilize GA Tracker 
$tracker = new GoogleAnalytics\Tracker('UA-12345678-9', 'example.com'); 
?> 

"products": [ 
     { 
      "title": "product", 
      "description": "description", 
      "thumbnail": "http://myurl.com/picture.jpg", 
      "price": "&pound;1.99", 
      "url": "http://link.com" 
     },$ga->setEvent("Category", "Action", "Label", "Value");] 

回答

0

當然,看看MIT Github上項目

https://github.com/ins0/google-measurement-php-client

它是一個PHP客戶端庫從服務器端與谷歌Analytics(分析)進行通信。 否則,你可以使用其他偉大的repositorys,看這裏

https://github.com/search?q=google-measurement&source=cc

+0

「當然」,因爲在它的工作?這個JSON所投入的網站將在某個地方以運行GA。 –

+0

你能解釋一下哪些方法無效嗎? – ins0

+0

感謝您的回覆@ ins0 明天當我看到它進入分析時,我會盡快回復您。 整個目的是真的要問,如果語法工作,因爲我基本上把PHP放入JSON在我上面的例子。 –