0

Scenario

I'm having trouble adding google analytics to a Unity3d interactive of mine. I've used GA several times in other languages and I am not expecting any issues once I can get going but the trouble is that I'm not able to get going.

What I've Tried

$ dotnet add package Google.Apis.Analytics.v3 --version 1.36.1.1268
Found more than one project in /Users/Jackson/Unity Projects/Soccer Goalie Proto/`. Please specify which one to use.

$ ls -la    
drwxr-xr-x 18 Jackson staff 576 Dec 27 20:55 .    
drwxr-xr-x 27 Jackson staff 864 Dec 27 11:11 ..    
-rw-r--r--@ 1 Jackson staff 6148 Aug 16 10:54 .DS_Store    
-rw-r--r-- 1 Jackson staff 453 Jun 5 2018 .collabignore    
drwxr-xr-x 16 Jackson staff 512 Dec 19 12:55 .git    
-rw-r--r-- 1 Jackson staff 438 Dec 19 12:55 .gitignore    
drwxr-xr-x 3 Jackson staff 96 Aug 22 14:07 .vs    
-rw-r--r-- 1 Jackson staff 26291 Dec 19 12:59 Assembly-CSharp-Editor-firstpass.csproj    
-rw-r--r-- 1 Jackson staff 26692 Dec 19 12:59 Assembly-CSharp-Editor.csproj    
-rw-r--r-- 1 Jackson staff 32252 Dec 19 12:59 Assembly-CSharp-firstpass.csproj    
-rw-r--r-- 1 Jackson staff 35337 Dec 19 12:59 Assembly-CSharp.csproj    
drwxr-xr-x 45 Jackson staff 1440 Dec 19 17:49 Assets    
drwxr-xr-x 28 Jackson staff 896 Dec 20 12:32 Library    
drwxr-xr-x 3 Jackson staff 96 Aug 16 10:14 Packages
drwxr-xr-x 19 Jackson staff 608 Dec 19 12:55 ProjectSettings    
-rw-r--r-- 1 Jackson staff 2421 Dec 19 12:56 Soccer Goalie Proto.sln
-rw-r--r--@ 1 Jackson staff 624884 Dec 27 20:47 google.apis.analytics.v3.1.36.1.1268.nupkg

I attempted adding Assembly-CSharp.csproj to a number of places in the command with no luck. I even downloaded the .nupkg and used nuget install but I couldn't get that to work either.

Question

What do I need to do to get this package installed to my c# project?

Note

I've already tried the google analytics plugin for Unity3d but it seems to only work for android / ios (I'm trying to get analytics for an EXE build)

Jacksonkr
  • 31,583
  • 39
  • 180
  • 284
  • The regular .NET Google API packages aren't supported on Unity I'm afraid. I think it would be better to try to get the Unity-specific package working with your EXE build - I'd expect that to work, even if there aren't instructions for it at the moment. – Jon Skeet Dec 28 '18 at 17:07
  • @JonSkeet What about making webrequests from c# to mimic javascript api calls? It seems like that might be less work but I'd rather get your opinion. What would you do? – Jacksonkr Dec 28 '18 at 17:14
  • 1
    You could potentially do that, but you should review the Analytics licence text first. I don't know anything about the legal side of things I'm afraid. I would definitely try to get the Unity-specific package working first. – Jon Skeet Dec 28 '18 at 17:31

1 Answers1

0

Option A

After researching this a bit it seems google offers REST data out but not REST data in. I've applied for a Google Analytics Live Tracking beta which offers a REST api so that I can send data in. I'll know within 24hrs if I've been accepted.

Option B

If I can't get into option A then I'm going to create a PHP webserver on the same machine running the interactive. I'll have c# send a webrequest to the PHP server which can then use the PHP GA SDK to send the track to google analytics.

Option C

I'm not sure why I didn't sniff an outgoing request first. Looking at one now I may be able to mimic the PUT/POST request to send data directly to GA with a c# web request. Here's a sample request I found online:

http://www.google-analytics.com/collect
?v=1
&tid=UA-XXX-Y
&cid=35009a79-1a05-49d7-b876-2b884d0f825b
&an=My%20Awesom%20APP
&aid=com.daimto.awesom.app
&av=1.0.0&aiid=com.daimto.awesom.installer
&t=event
&ec=list
&ea=accounts
&userclicked
&ev=10

Solution

I ultimately went with Unity Analytics, which is free (for now)

Jacksonkr
  • 31,583
  • 39
  • 180
  • 284