Giter Site home page Giter Site logo

dotnet / windows-sdk-for-google-analytics Goto Github PK

View Code? Open in Web Editor NEW
102.0 38.0 33.0 150 KB

SDK to connect to Google Analytics from Windows Store (UWP) Apps, Windows desktop apps written with .NET, and Xamarin Apps

License: MIT License

Batchfile 0.70% C# 56.31% C++ 41.30% C 0.10% CSS 0.17% HTML 0.36% JavaScript 1.06%

windows-sdk-for-google-analytics's Introduction

Windows SDK for Google Analytics™

This repo is archived. A .NET Standard-based version is maintained by @LindaLawton here.

The Windows SDK for Google Analytics makes it easy to connect your Universal Windows Apps to Google Analytics Mobile App accounts.

The SDK uses Google's measurement protocol to send HTTP requests with user interaction data to Google's Universal Analytics Services. The SDK also supports the debug endpoint which will allows developers to test and validate their hits.

The SDK supports tracking for the following interaction (Hit) types:

The implementation supports:

Getting Started

Please read our Getting Started page for detailed information on pre-requisites, samples, and getting the nuget packages for the SDK.

Release notes/Update history:

v1.5.0.0. Feb 2017. This is our initial release, though our SDK is an iteration on this prior project on codeplex.

  • Please see supported features above.
  • Converged the APIs so that the C# and WinRT SDKs would be seamless. In the convergence, we deprecated a few features from old SDK (in codeplex), so look at our FAQ, for porting your code from older SDK to this one.
  • We tweaked the APIs so they mapped closer to the Google Analytics Android SDK. This way folks familiar with the API on other platform could more easily reuse their knowledge with our SDK.

Useful links

About this SDK

This SDK is intended to have feature parity as well as API similarity (adjusted for .NET and WinRT conventions) with the official Google Analytics SDK for Android.

Feedback and Requests

Please use the issues page to submit any bugs, comments or questions, and feature requests.

Contributing

We accept contributions to code, samples, and docs. Please submit pull requests.

.NET foundation

This project is supported by the .NET Foundation

windows-sdk-for-google-analytics's People

Contributors

jaimerodriguez avatar lindalawton avatar martinwoodward avatar superusercode avatar terrajobst avatar tiembo avatar timgreenfield avatar yinyue200 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

windows-sdk-for-google-analytics's Issues

Broken Connection

For some reason, I have followed tutorials and even used the sample code with my tracking ID, but I am unable to see any data in the google analytics portal. The result in the sample shows valid = true. Aside from that I have NO IDEA how to debug and see even if I am hitting the google analytics successfully.This is the tracking ID I am using for testing UA-102555648-1.

Cannot make the sample code working using the Windows SDK C# with UWP

Hi,

We are trying to make the sample code for GA working and having issues with it. Here are the steps that we have followed.

  • Created Google Analytic account for Mobil and got the GA tracking ID
  • Tested with Google Analytic tool to make sure we see the hit
    Hit builder
  • Now following the instructions on this page
    Windows SDK for Google Analytics
  • Opened Visual Studio 2015
  • Installed from this link
    Windows SDK Plugin
  • Downloaded the sample code from here:
    Sample Code from GitHub
  • Opened the project in Visual Studio 2015
  • Updated the code with the new tracking Id that we generated earlier
  • Executed the project and got the UI with buttons
  • Clicked on the buttons - Custom Events, Page View, Social activity, etc but there was no activity registered on the GA side. There was no error and got successful confirmation when we click the buttons.
  • here is an example when we click on the 'Custom events' button
    request:
    v:1
    tid:UA-93543126-1
    cid:a55c9fbb-c64a-43f3-8091-f3b471cba695
    an:2ec26bec-8977-490d-ab91-da6243a8c6aa
    av:1.0.1.0
    cd:Main
    sr:5280x1147
    vp:795x587
    ul:en-US
    t:event
    ec:Test Category
    ea:New User-click
    el:level5
    ev:32
    dp:MainScreen

response
{
"hitParsingResult": [ {
"valid": true,
"parserMessage": [ ],
"hit": "/debug/collect?v=1\u0026tid=UA-93543126-1\u0026cid=a55c9fbb-c64a-43f3-8091-f3b471cba695\u0026an=2ec26bec-8977-490d-ab91-da6243a8c6aa\u0026av=1.0.1.0\u0026cd=Main\u0026sr=5280x1147\u0026vp=795x587\u0026ul=en-US\u0026t=event\u0026ec=Test Category\u0026ea=New User-click\u0026el=level5\u0026ev=32\u0026dp=MainScreen\u0026z=319909151"
} ],
"parserMessage": [ {
"messageType": "INFO",
"description": "Found 1 hit in the request."
} ]
}

  • So note that we have a successful execution but there is no Hit on the GA side. We don't see any activity on the GA console.

Any direction/feedback/suggestion/ideas is appreciable.

Thanks.

BUG. hits object isn't locked in DispatchQueuedHits()

Current source of ServiceManager class contains method:

    async Task DispatchQueuedHits(IEnumerable<Hit> hits)
    {
        using (var httpClient = GetHttpClient())
        {
            var now = DateTimeOffset.UtcNow;
            foreach (var hit in hits)
            {
                if (isEnabled && (!ThrottlingEnabled || hitTokenBucket.Consume()))
                {
                    // clone the data
                    var hitData = hit.Data.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
                    hitData.Add("qt", ((long)now.Subtract(hit.TimeStamp).TotalMilliseconds).ToString());
                    await DispatchHitData(hit, httpClient, hitData);
                }
                else
                {
                    lock (hits) // add back to queue
                    {
                        this.hits.Enqueue(hit);
                    }
                }
            }
        }
    }

where lock statement locks incorrect object, instead of lock (hits) it should be lock (this.hits).
So correct code should be:

    async Task DispatchQueuedHits(IEnumerable<Hit> hits)
    {
        using (var httpClient = GetHttpClient())
        {
            var now = DateTimeOffset.UtcNow;
            foreach (var hit in hits)
            {
                if (isEnabled && (!ThrottlingEnabled || hitTokenBucket.Consume()))
                {
                    // clone the data
                    var hitData = hit.Data.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
                    hitData.Add("qt", ((long)now.Subtract(hit.TimeStamp).TotalMilliseconds).ToString());
                    await DispatchHitData(hit, httpClient, hitData);
                }
                else
                {
                    lock (this.hits) // add back to queue
                    {
                        this.hits.Enqueue(hit);
                    }
                }
            }
        }
    }

Can't install package for a simple winform in VS 2015

I created a sample winform application in visual studio 2015, which is targeting .net 4.5.2. When I tried to add the sdk to my project, i'm getting this error:

Could not install package 'UWP.SDKforGoogleAnalytics.Managed 1.5.2'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.5.2', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

Do I miss anything? What is the minimum requirement for adding the SDK?

Device Tracking

I started using the sdk and I noticed that it does not correctly track the device type and model, it only shows a Lumia 435 device or a WinRT tablet, and this is not the device I used for testing. I tried with a Lumia 550 and a Lumia 640 and they both appear as Lumia 435 in the devices section of the google analytics stats.

UWP 16299 issue

Seems after upgrading on 16299 build analytics stop working.

Performance problems?

Why library doesn't use ConfigureAwait(false) method. Is library really require the same context in all places? I'm asking because such code in library is a potential deadlock issue on client platform with UI thread.
I think you can slightly speed up code and remove many problems, if add ConfigureAwait(false) to code, especially in DispatchQueuedHits(), DispatchImmediateHit() and DispatchHitData().

BUG. Hits queue isn't clearing in DispatchAsync().

If TrackerManager.DispatchPeriod is set in non zero value, for example 10 seconds, then all hits that were collected from application startup time will be sent every 10 seconds. This is because DispatchAsync() method doesn't clear hits queue for hits that are sent.
Current method's code should be changed to :

        public async Task DispatchAsync()
        {
            if (!isEnabled) return;

            Task allDispatchingTasks = null;
            lock (dispatchingTasks)
            {
                if (dispatchingTasks.Any())
                {
                    allDispatchingTasks = Task.WhenAll(dispatchingTasks);
                }
            }
            if (allDispatchingTasks != null)
            {
                await allDispatchingTasks;
            }

            if (!isEnabled) return;

            Hit[] hitsToSend;
            lock (hits)
            {
                hitsToSend = hits.ToArray();
                hits.Clear(); // clear queue.
            }
            if (hitsToSend.Any())
            {
                await RunDispatchingTask(DispatchQueuedHits(hitsToSend));
            }
        }

Please, fix library.

AutoAppLifetimeMonitoring and Hangs (esp. from China)

When AutoAppLifetimeMonitoring is set, an operating system suspend event will wait for all dispatched hits to complete before completing the suspend handler, via a deferral request.

Unfortunately - the UWP lifecycle gives the app at most five seconds to respond to the suspend request. We found that our app was unable to consistently reach the server within that timeframe, particularly in the Chinese market. This showed up as a high "hang" rate for the app in the Microsoft Store Dashboard, particularly from East Asia / Southeast Asia.

I'd suggest that this package should perhaps:

  • suspend handler: if 4.9s passes without completing hits, return control to operating system
  • OR warn about this consequence in documentation, and perhaps not enable this option by default in the examples.

guidance

I am new in both Google Analytics and your SDK.
A naive question probably. Why you say only about mobile analytics?
is not possible with your SDK to get alerts for analytics in web sites?
thanks

Use full system version in UserAgent ?

What do you think of returning the full system version (10.0.14393.693) in the UserAgent instead of only returning 10.0 ?

I think that it can be very interesting to know what build our Users are using.

PageView instead of ScreenView

In trying to use this library when building a WPF Visual Studio extension, I used the Managed Core code and wrote my own PlatformInfoProvider, etc. I noticed that the call was being made for a ScreenView much like Google Analytics is requesting a PageView. I don't know if I had another setting wrong, but basically, the ScreenView wasn't registering in GA, but it was coming up as some sort of an anonymous hit? Not sure exactly. Once I added this method to the HitBuilder.cs, and used it instead of the HitBuilder.CreateScreenView, it worked just fine.

private const string HitType_Pageview = "pageview";

public static HitBuilder CreatePageView(string pageName = null, string title = null)
       {
           var data = new Dictionary<string, string>();
           data.Add("t", HitType_Pageview);
           if (pageName != null) data.Add("dp", pageName);
           if (title != null) data.Add("dt", title);
           return new HitBuilder(data);
       }

Managed integration tests failing

With the additional of the new FireOnUIThread property, the integration tests are not compiling with the managed version. Also, if you comment out that 1 test. There are 5 failing tests.

IsDebug documentation/functionality

First of all, thanks so much for creating this SDK. I've already submitted my first implementation in an app using this. (And removed the difficult-to-use Application Insights.)

One things that might help new developers to this SDK is to explain the IsDebug a bit more. The documentation does not mention it, but when IsDebug is true, no data will be recorded in Google Analytics, so it will appear to be non-functional.

I now understand that setting IsDebug to true switches from live analytics reporting to the in-app events, but new users are only told that the events are wired up -- not that it does not also report the data to Google.

So I'd recommend either updating the documentation or else simultaneously reporting the data to Google and the wired-up debug events.

EDIT: One other minor comment that might help new developers. In the sample code it shows the Tracker object being set in the App.xaml.cs file, within the if (e.PrelaunchActivated == false) { } block. For me, this caused an error to be thrown during certification when it tested the Prelaunch capability. So I took the Tracker assignment code out of that block and placed it within an if statement:

if (Tracker == null) {
Tracker = AnalyticsManager.Current.CreateTracker("UA-xxxxxxxx-x");
AnalyticsManager.Current.IsDebug = false;
AnalyticsManager.Current.ReportUncaughtExceptions = true;
AnalyticsManager.Current.AutoAppLifetimeMonitoring = true;
}

if (e.PrelaunchActivated == false) {
...
}

How do I track User properties?

Hi,

How do I log user properties like email, userid, user session? Does the user session is tracked by default?

Additionally, Does SDK auto track the following params:

  1. Device OS, Model
  2. App Version

If not, How do we track this events?

Thanks

error install package

Hi,
I wish to add windows-sdk-for-google-analytics in my project but when i tried to add a UWP.SDKforGoogleAnalytics.Native from nuget Package Manager i receive the error.

Error: The 'UWP.SDKforGoogleAnalytics.Native 1.5.1' package could not be installed. You are trying to install on a project that is destined to 'MDD, Version = v8.1', but the package does not contain frame references or framework files. For more information, contact the author of the package.

Do you have a solution?

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.