簡體   English   中英

將屬性添加到Cordova插件的上下文中以獲取Application Insights

[英]Add properties to context in cordova plugin for Application Insights

我將Cordova插件與Application Insight一起使用,命名為cordova-plugin-ms-appinsights( https://github.com/MSOpenTech/cordova-plugin-ms-appinsights/blob/master/README.md ),並嘗試將屬性添加到在上下文中,該應用程序將通過每個請求發送其他信息,例如我的應用程序的代號。

我嘗試如下:

appInsights.context.application.codename =“代號app”; appInsights.trackEvent(“我的事件”);

這是行不通的。 我可以在上下文中添加其他信息嗎?

有兩個問題:

1)Cordova插件似乎使用了JS SDK的舊版本。 您可以嘗試將舊版本的舊版本刪除后手動對其進行更新(從https://github.com/Microsoft/ApplicationInsights-JS/blob/master/dist/ai.0.js中獲取最新版本)

2)尚未發布向所有遙測項目添加數據的功能。 它是最近實現的- 請參見github上的JS SDK commit 您可以稍等片刻,直到發布它,或者從master那里獲取最新版本並自己編譯(並從/JavaScript/min/ai.min.js獲取結果)

一個有問題的替代方法可能是在諸如trackEvent()之類的SDK方法之上創建一個包裝器,以添加所需的數據(對不起,因為我自己沒有使用cordova插件,所以給了您等效的JS SDK代碼):

// this is you implementation of custom data to be attached
// to all telemetry items.
// It needs to return JSON - as it's expected format for custom properties.
// In this specific case you'll create a custom property 'hey' with value 'yo'
var getMyDataJson = function() {
  return { hey: "yo"};
}    

// this is your wrapper, you'll call it instead of appInsights.trackEvent()
var myTrackEvent = function(data) {
  var toBeAttachedToAllItems = getMyDataJson();
  appInsights.trackEvent(data, toBeAttachedToAllItems);
}
<...>
// somewhere later you track your telemetry
// this will call your getMyDataJson() function which'll attach
// custom data to your event.
myTrackEvent("tracked!")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM