attackpattern / csharpanalytics Goto Github PK
View Code? Open in Web Editor NEWGoogle Analytics for Windows 8, Windows Phone & desktop applications
Google Analytics for Windows 8, Windows Phone & desktop applications
Has anybody considered adding support for ASP.NET projects so we track our server-side C# code in webform and/or MVC applications?
There was an error deserialzing the object of type "CSharpAnalytics.Sessions,SessionState. The data at the root level is invalid. Line1, position 1.
If the user sets 'SetOptOut' before calling Start the library throws an IOException when trying to save session settings.
This is causes due to thread race when SetOptOut saves the session (BaseAutoMeasurement line:157) and Start tries to do the same (BaseAutoMeasurement line:77).
Just wanted to give this library a whirl. Seems pretty easy to use, which was a big bonus for me. I had things working with these lines for my setup:
AutoMeasurement.Instance = new WinFormAutoMeasurement();
AutoMeasurement.Instance.Start(new MeasurementConfiguration("UA-60679857-1", Application.ProductName, Application.ProductVersion), "Debug");
And then on a screen I'd call
AutoMeasurement.Client.TrackScreenView("My Screen");
Now on startup (specifically, only if I include the .Start() line, I get the following exception:
There was an error deserializing the object of type System.Collections.Generic.List
1[[System.Uri, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]. The data at the root level is invalid. Line 1, position 1. at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver) at System.Runtime.Serialization.XmlObjectSerializer.ReadObject(XmlDictionaryReader reader) at System.Runtime.Serialization.XmlObjectSerializer.ReadObject(Stream stream) at CSharpAnalytics.Serializers.AppDataContractSerializer.<Restore>d__0
1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter1.GetResult() at CSharpAnalytics.WinFormAutoMeasurement.<Load>d__0
1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at CSharpAnalytics.BaseAutoMeasurement.d__9.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at CSharpAnalytics.BaseAutoMeasurement.d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.b__1(Object state)
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
The data at the root level is invalid. Line 1, position 1.
at System.Xml.XmlExceptionHelper.ThrowXmlException(XmlDictionaryReader reader, String res, String arg1, String arg2, String arg3)
at System.Xml.XmlUTF8TextReader.Read()
at System.Xml.XmlBaseReader.IsStartElement()
at System.Xml.XmlBaseReader.IsStartElement(XmlDictionaryString localName, XmlDictionaryString namespaceUri)
at System.Runtime.Serialization.XmlReaderDelegator.IsStartElement(XmlDictionaryString localname, XmlDictionaryString ns)
at System.Runtime.Serialization.XmlObjectSerializer.IsRootElement(XmlReaderDelegator reader, DataContract contract, XmlDictionaryString name, XmlDictionaryString ns)
at System.Runtime.Serialization.DataContractSerializer.InternalIsStartObject(XmlReaderDelegator reader)
at System.Runtime.Serialization.DataContractSerializer.InternalReadObject(XmlReaderDelegator xmlReader, Boolean verifyObjectName, DataContractResolver dataContractResolver)
at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver)
I feel like it's trying to restore some state or something, but I've blown away my bin directory and I've checked source control to ensure I have no other changes. It just stopped working out of (seemingly) nowhere and now I can't really do all that much.
Definite props for putting something together that's so easy to use though.
Hi is there a way to set a proxy to AutoMeasurement?
Application version is tracked as Major.Minor.Revision.Build , which is not the same pattern as in AssemblyInfo nor in the package manifest.
Application version should be tracked as Major.Minor.Build.Revision
MeasurementConfiguration.FormatVersion
Session start and session end time stamps registered at GA are very often too late relative to other events.
This happens when session start and session end events are queued when there is no internet connection.
But it also happens whith all session end events, because session end events are only sent at the time when a new session is started.
Problem source: “QT” (Queue Time ) parameter is not appended to “SC” (Session Control) events.
Steps to Reproduce:
I have been testing our this library and the Measurement Protocol in general. I cant seem to get sessions to end correctly. I have a very basic application to test with. In the example below I start the app, view one screen and close the app; then I repeat this one time with the same cid. I see the data come in with GA real time. I would expect to see 1 user and 2 sessions; but I don't... I see 1 user and 1 session. Im assuming that session management isn't being handled correctly on the client side and its falling back to GA's default of 30 min to define a session. Any ideas?
SESSION START
v=1&tid=UA-42299003-2&cid=efcca950-c40d-4932-af8f-01f7da12dbb3&aip=0&an=Tester&av=1.0.0&ul=en-us&sr=800x600&t=appview&cd=app&sc=start&z=527986040
HOME APPVIEW
v=1&tid=UA-42299003-2&cid=efcca950-c40d-4932-af8f-01f7da12dbb3&aip=0&an=Tester&av=1.0.0&ul=en-us&sr=800x600&t=appview&cd=home&z=1994456977
SESSION END
v=1&tid=UA-42299003-2&cid=efcca950-c40d-4932-af8f-01f7da12dbb3&aip=0&an=Tester&av=1.0.0&ul=en-us&sr=800x600&t=appview&cd=app&sc=end&z=2039537302
5s delay...
APP START
v=1&tid=UA-42299003-2&cid=efcca950-c40d-4932-af8f-01f7da12dbb3&aip=0&an=Tester&av=1.0.0&ul=en-us&sr=800x600&t=appview&cd=app&sc=start&z=2090727250
HOME APPVIEW
v=1&tid=UA-42299003-2&cid=efcca950-c40d-4932-af8f-01f7da12dbb3&aip=0&an=Tester&av=1.0.0&ul=en-us&sr=800x600&t=appview&cd=home&z=39349359
SESSION END
v=1&tid=UA-42299003-2&cid=efcca950-c40d-4932-af8f-01f7da12dbb3&aip=0&an=Tester&av=1.0.0&ul=en-us&sr=800x600&t=appview&cd=app&sc=end&z=1496245515
First I want to thank you for this great and easy to use lib. Do you consider to support also .net 4.0 Client Profile Applications in the near future?
Hi Damien,
The NuGet package seems to miss the Winforms project, it does install only the dll for net45 and so CSharpAnalytics.AutoMeasurement, and others cannot be used.
Building from the sources and using the CSharpAnalytics.WinForms project is working fine.
Can you correct the NuGet package ?
Thanks in advance.
It will be null when called by native code, and this is causing my application to crash. When I remove those calls, everything works fine.
I was fiddling with our app's ability to handle network availability and I started getting null reference exceptions in BaseAutoMeasurement::Request(). It was complaining on the first line:
if (sessionManager.VisitorStatus != VisitorStatus.Active)
because sessionManager was still null. I looked into it and I think the problem is in BaseAutoMeasurement::Start(). Currently, it looks like this:
await StartRequesterAsync();
var sessionState = await Load<SessionState>(SessionStorageName);
sessionManager = new SessionManager(sessionState, configuration.SampleRate);
if (delayedOptOut != null) SetOptOut(delayedOptOut.Value);
But if I change it to:
var sessionState = await Load<SessionState>(SessionStorageName);
sessionManager = new SessionManager(sessionState, configuration.SampleRate);
await StartRequesterAsync();
if (delayedOptOut != null) SetOptOut(delayedOptOut.Value);
it stops throwing exceptions. I'm guessing because when the Requester is fired up, it immediately checks for prior requests, queues them, and starts processing them. Unfortunately, sessionManager is initialized later, so its not there, and it fails the Request() call.
So simply creating the SessionManager first solves the problem, but maybe there's a good reason it was created in the order its currently created!
We started to use the analytics library and it works ok. Right now if the user starts the WPF application, the Start method will try to save the current session. This ends with a race that one of the instances will throw an exception stating that the file is in use.
Unhandled exception occurred:System.IO.IOException: The process cannot access the file '[SOMEWHERE]\CSharpAnalytics-MeasurementSession' because it is being used by another process.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync)
at CSharpAnalytics.Serializers.AppDataContractSerializer.<Save>d__71.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at CSharpAnalytics.WpfAutoMeasurement.<Save>d__31.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at CSharpAnalytics.BaseAutoMeasurement.<Start>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>b__0(Object state)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
Great work and I really appreciate it!
The creation of the ContentViewActivity is missing a null in the second argument to make sure the other arguments are correctly mapped to the constructor.
public static void TrackContentView(this MeasurementAnalyticsClient analyticsClient, Uri documentLocation, string contentDescription,
string documentPath = null, string documentHostName = null)
{
if (analyticsClient == null) throw new ArgumentNullException("analyticsClient");
analyticsClient.Track(new ContentViewActivity(documentLocation, null, contentDescription, documentPath, documentHostName));
}
BR,
Peter
I've just start using your library -- it's working great! -- but we needed a Windows Phone 8.1 (non-Silverlight) version. I've actually already done the work; do you want me to to push the results back somehow? If so, I'd just need some instruction on how to merge my changes in so I don't clobber the Sliverlight code. I can add the 8.1 project easily enough (renamed as WindowsPhone81) but I had to touch a scattering of code and I'm not sure how to best make that work side-by-side with Silverlight. Use #if & the SILVERLIGHT define?
I've never actually contributed to an existing github project, so I apologize in advance -- I'm not sure what the protocol or procedure is.
Thanks!
AutoMeasurement.Client.TrackEvent
has parameters TrackEvent(string action, string category, ...
. But the Google Analytics shows the category first, then the action. More convenient would be to exchaneg these parameters TrackEvent(string category, string action, ...
Sent strings are malformed in the MeasurementAnalyticsClient.AdjustUriBeforeRequest
method, when a string contains chars =
or &
.
E.g. sending
AutoMeasurement.Client.TrackEvent("My Action", "My Custom Category", "My Label id=345");
results in sending label="My Label id"
only.
I've solved problem either by using UriFormat.UriEscaped
, or fix GetQueryParameters
method by q.Split(new char[] {'='}, 2)
. (Just one of this fix solved problem.)
Note: Such Uri construction, parsing and again construction is often source of problems. (My experience from several other applications.) Better to avoid it. Just construct the right Uri once and send it.
Hi,
I'm trying to use your library for a windows 8 app I'm developing.
I followed your instructions and integrated CSharpAnalytics to my project. I can now see get requests going to google analytics (using fiddler) and also see your Debug Info on my output window when debugging.
Everything seams to be working but unfortunately I can't see any data on Google analytics dashboard.
Am I doing something wrong?
Do you support WPF? I was looking at the .NET4.5 project, but could not figure out how to use it in a WPF app.
Hello,
When I'm invoking your lib from a com-visible dll the GetEntryAssembly() is always null and the app crashes do think it is safe to use GetExecutingAssembly() instead?
Thank you
Exception: System.UnauthorizedAccessException
Message: Access to the path 'C:\Users\jcameron\AppData\Roaming\MangoApps\CSharpAnalytics-MeasurementSession' is denied.
Stack:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync)
at CSharpAnalytics.Serializers.AppDataContractSerializer.d__71.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at CSharpAnalytics.WinFormAutoMeasurement.<Save>d__3
1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at CSharpAnalytics.BaseAutoMeasurement.d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.b__0(Object state) < Less
How to send pageview hits -
Is this request right ? Becasue it does not work for me
Please, make internal classes in CSharpAnalytics.Environment
and CSharpAnalytics.Serializers
public, so they may be reused when writing custom AutoMeasurement.
I've seen #43, and I'm using v.1.2.1 via NuGet.
I have multiple machines which get this issue (shown below).
I'm not sure what's causing it, but I simply CANNOT manage to catch the exception! It's always an unhandled exception.
Any suggestions how to handle the exception?
`System.Xml.XmlException: There are multiple root elements. Line 1, position 2.
at System.Xml.XmlExceptionHelper.ThrowXmlException(XmlDictionaryReader reader, String res, String arg1, String arg2, String arg3)
at System.Xml.XmlBaseReader.EnterScope()
at System.Xml.XmlUTF8TextReader.ReadStartElement()
at System.Xml.XmlUTF8TextReader.Read()
at System.Xml.XmlBaseReader.ReadEndElement()
at System.Runtime.Serialization.XmlReaderDelegator.ReadEndElement()
at System.Runtime.Serialization.ClassDataContract.ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context)
at System.Runtime.Serialization.XmlObjectSerializerReadContext.ReadDataContractValue(DataContract dataContract, XmlReaderDelegator reader)
at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator reader, String name, String ns, Type declaredType, DataContract& dataContract)
at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator xmlReader, Type declaredType, DataContract dataContract, String name, String ns)
at System.Runtime.Serialization.DataContractSerializer.InternalReadObject(XmlReaderDelegator xmlReader, Boolean verifyObjectName, DataContractResolver dataContractResolver)
at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver)
System.Runtime.Serialization.SerializationException: There was an error deserializing the object of type CSharpAnalytics.Sessions.SessionState. There are multiple root elements. Line 1, position 2.
at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver)
at System.Runtime.Serialization.XmlObjectSerializer.ReadObject(XmlDictionaryReader reader)
at System.Runtime.Serialization.XmlObjectSerializer.ReadObject(Stream stream)
at CSharpAnalytics.Serializers.AppDataContractSerializer.d__01.MoveNext() at End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at CSharpAnalytics.WinFormAutoMeasurement.<Load>d__0
1.MoveNext()
at End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at CSharpAnalytics.BaseAutoMeasurement.d__0.MoveNext()
at End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c.b__6_1(Object state)
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()`
Allow to use URL https://www.google-analytics.com/debug/collect
or any custom URL to send the requests.
Calling Window.Current.CoreWindow.Bounds; from the WindowsStoreEnvironment class throws a null reference exception. Window.Current is null.
I am using AutoMeasurement
class from a non-gui library and it need to know, if the AutoMeasurement
is initialized or not. (AutoMeasurement.Instance
throws an exception.) Some flag like
public static bool Initialized
{
get { return _instance != null; }
}
There is a build break because of ShouldUsePostForRequest in master with no definition. See:
a/Source/CSharpAnalytics/Network/HttpWebRequester.cs:
internal static HttpWebRequest CreateRequest(Uri requestUri, bool writePostBody = true)
{
return requestUri.ShouldUsePostForRequest()
? CreatePostRequest(requestUri, writePostBody)
: CreateGetRequest(requestUri);
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.