Giter VIP home page Giter VIP logo

cordova-plugin-ms-appinsights's Introduction

This plugin is no longer supported or maintained by Microsoft. If you wish to continue this project, please feel free to fork it.

Application Insights plugin for Apache Cordova apps

This plugin allows you to add an Application Insights to your Apache Cordova app. Application Insights is a techonogy that sends telemetry from your app to the Azure portal.

More info about Application Insights technology could be found here

To use this plugin you'll need an account in Microsoft Azure. You might already have access to a group account through your organization, or you might want to get a Pay-as-you-go account. (While Application Insights is in Preview, it's free.)

For more API documentation see sample application and JSDoc for exposed functionality stored in www subfolder.

Supported platforms

  • Android
  • iOS
  • Windows

Sample usage

Application Insights API is available through window.appInsights object. To start using it you don't have to initialize it, just start calling its' methods

// This will send a custom-defined event to your appInsights account
var eventData = { ButtonId: "trackSingleEvent", Timestamp: new Date() };
appInsights.trackEvent('click', eventData);

// This will send data about how long some action is performed
appInsights.startTrackEvent("longRunningTask");
// Emulate some long-running action through `setTimeout`
setTimeout(function () {
     // When task is finished, call 'stopTrackEvent' with the same event as in 'startTrackEvent'
    appInsights.stopTrackEvent("longRunningTask");
}, 10000);

// This will send an exception information to your appInsights account
try {
    // Do some logic here which may
    throw new Error("Sample Error");
} catch (err) {
    // Catch an error and send it to appInsights
    appInsights.trackException(err);
}

More information about AppInsights API could be found here

Installation Instructions

Prerequisites

To build and run sample application

  • Clone this repository into a directory of your choice

    git clone https://github.com/MSOpenTech/cordova-plugin-appinsights.git

  • Create a cordova project and add the platforms you want to support

    cordova create AppInsightsSample --copy-from="cordova-plugin-appinsights/sample"

    cd AppInsightsSample

    cordova platform add android

    cordova platform add windows

    cordova platform add ios

  • Add the plugin to your project

    cordova plugin add ../cordova-plugin-appinsights --variable INSTRUMENTATION_KEY=<your_key>

  • Set up intrumentation key for AppInsights API. Modify the following line in config.xml file at the project root

    <preference name="instrumentation_key" value="$INSTRUMENTATION_KEY">

replace $INSTRUMENTATION_KEY with your key.

  • optional: install battery and network status plugins to track their events to AppInsights as well.

    cordova plugin add cordova-plugin-battery-status cordova-plugin-network-information

  • Build and run application: cordova run.

Copyrights

Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

cordova-plugin-ms-appinsights's People

Contributors

mattmccleary avatar panarasi avatar ryanlowdermilk avatar sgrebnov avatar southwood avatar sureshja avatar vladimir-kotikov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cordova-plugin-ms-appinsights's Issues

appInsight object undefined

I'm trying to add app insights object on my cordova project, I added the plugin with the instrumentation key as instructed by the readme file.

When I use appInsights.trackEvent() in my JavaScript file I get an error which says that the appInsights object is undefined. The package is not added to the java directory even though I successfully added the cordova-plugin-ms-appinsights plugin to my cordova project.

Invalid instrumentation key

Hi,

I configured the plugin inside my app and the app insights returns an error 400 invalid instrumentation key. Then I created an empty app, and included the plugin again, and I got the same error 400.

Can you help me?

before_prepare script causing build to fail

Hi,
The before_prepare script is causing cordova build to fail with error:
Cannot find module '../configparser/ConfigParser'

This line in the script var ConfigParser = ctx.requireCordovaModule('../configparser/ConfigParser');
is causing the error.

When i change it to: var ConfigParser = ctx.requireCordovaModule('cordova-common').ConfigParser;
The build completes OK.

Plugin causes Ripple to go into a redirect loop

I have an issue where Ripple gets in a redirect loop simply after adding the plugin to the project. Here are the repro steps:

  • Create a new Cordova project in Visual Studio 2015
  • Add the plugin via git
  • Launch the project using Ripple either for iOS or Android

I find that the page will continue to redirect and continue to load itself over and over while the Visual Studio debugger is attached. If I detach the debugger, the redirect loop stops and the application loads normally. This is even before I add a single line of code to make use of the plugin.

I don't expect the plugin to necessarily work in Ripple, but it would be nice if I could still use it to debug my app.

SCRIPT7002: XMLHttpRequest: Network Error 0x2ee4, Could not complete the operation due to error 00002ee4

This problem only affects to WindowsPhone 8.1 platform (not tested in other Windows platforms) it does not happen (works like a charm) in iOS or Android. We also have detected that Windows Phone browser detects https://dc.services.visualstudio.com SSL certificate as invalid.

Steps followed to create a new app:

> git clone https://github.com/MSOpenTech/cordova-plugin-appinsights.git
> cordova create TAI
> cd TAI
> cordova platform add windows
> cordova plugin add ../cordova-plugin-appinsights --variable INSTRUMENTATION_KEY=%YOUR_KEY%
> cordova plugin add cordova-plugin-battery-status cordova-plugin-network-information
> cordova build windows
> start platforms/windows/CordovaApp.sln

Now select CordovaApp.Phone as startup project, debug on device, and in the Javascript console write:

appInsights.trackEvent('TAI');
appInsights.flush();

The result of both commands should be undefined and the event must be added to the events list.

If you do cordova platform remove windows and cordova platform add windows it still working well.

How to reproduce the problem

From the previows installation just add a plugin (it seems that does not matter which, almost with any plugins the problem appears):

> cordova plugin add cordova-plugin-camera
> cordova build windows
> start platforms/windows/CordovaApp.sln

Make sure that you have selected CordovaApp.Phone as startup project.
Start debug on device, and in the Javascript console write:

appInsights.trackEvent('TAI-with-camera');
appInsights.flush();

The result is:

undefined
SCRIPT7002: XMLHttpRequest: Network Error 0x2ee4, Could not complete the operation due to error 00002ee4
File: index.html
Failed to send telemetry:

And no event is shown is shown in the appInsights portal.

But, if we now do on the same project:

> cordova plugin remove cordova-plugin-camera
> cordova build windows
> start platforms/windows/CordovaApp.sln

Make sure that you have selected CordovaApp.Phone as startup project.
Start debug on device, and in the Javascript console write:

appInsights.trackEvent('TAI-without-camera');
appInsights.flush();

The result stills the same:

undefined
SCRIPT7002: XMLHttpRequest: Network Error 0x2ee4, Could not complete the operation due to error 00002ee4
File: index.html
Failed to send telemetry:

If I do

> cordova remove platform windows
> cordova add platform windows
> cordova build windows
> start platforms/windows/CordovaApp.sln

and repeat test, problem still appearing.

Note: I'm using VS Express 2013 for Windows 12.0.30723.00 Update 3, and Windows 8.1 Pro 6.3.9600, tested on few devices (Nokia Lumia 925 RM-892 & MS Lumia 640 XL Dual SIM)

Failed to send telemetry - Android

I get this error when trying to do appInsights.TrackException on android device. ios works fine.

Failed to send telemetry:
{"itemsReceived":6,"itemsAccepted":0,"errors":[{"index":0,"statusCode":400,"message":"109: Field 'method' on type 'StackFrame' is required but missing or empty. Expected: string, Actual: "},{"index":1,"statusCode":400,"message":"109: Field 'method' on type 'StackFrame' is required but missing or empty. Expected: string, Actual: "},{"index":2,"statusCode":400,"message":"109: Field 'method' on type 'StackFrame' is required but missing or empty. Expected: string, Actual: "},{"index":3,"statusCode":400,"message":"109: Field 'method' on type 'StackFrame' is required but missing or empty. Expected: string, Actual: "},{"index":4,"statusCode":400,"message":"109: Field 'method' on type 'StackFrame' is required but missing or empty. Expected: string, Actual: "},{"index":5,"statusCode":400,"message":"109: Field 'method' on type 'StackFrame' is required but missing or empty. Expected: string, Actual: "}]}

TrackEvent event data does not include 'duration'

After calling:

appInsights.startTrackEvent("MyEvent");
// doing a server request...then...
appInsights.stopTrackEvent("MyEvent", {
    Institute: "MyInstitute", 
    ApiUrl: "http//myinstitute.com/"}
);

I get the following event sent to the server, but it does not contain a 'duration' property:

{
        "time": "2015-12-03T02:00:09.815Z",
        "iKey": "dcc9cae1-142b-47b4-bbcb-04e0d0881645",
        "name": "Microsoft.ApplicationInsights.Event",
        "tags": {
            "ai.device.id": "3D0AD03B-8B46-431A-BEF5-FF01B96BFFFF",
            "ai.device.locale": "unknown",
            "ai.device.os": "Android",
            "ai.device.osVersion": "4.x.x",
            "ai.device.screenResolution": "360X640",
            "ai.internal.sdkVersion": "0.14.0.0",
            "ai.operation.id": "2C51ED2E-AD0C-4A34-85C5-925A50854ADD",
            "ai.session.id": "09BA19CD-C6D3-4777-9497-48120BD41D27",
            "ai.session.isNew": "false",
            "ai.user.id": "BE45A326-5C7E-4232-AA31-6ACCC0F6FFFF"
        },
        "data": {
            "baseType": "EventData",
            "baseData": {
                "ver": 2,
                "name": "MyEvent",
                "properties": {
                    "Institute": "MyInstitute",
                    "ApiUrl": "http://myinstitute.com"
                }
            }
        }
    }

When using startTrackPage() and endTrackPage() the 'duration' property is sent correctly.

Add properties to context

I use cordova plugin with Application Insight and I tried to add my properties to context, that through each request application will send additional info, for example code name of my application.

I tried as below:

appInsights.context.application.codename = "code name app";
appInsights.trackEvent("my event");

and this did not work. Can I add additional info to context?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.