0

I'm sending simple messages to Google Analytics from a Silverlight app. They look something like this (data changed):

http://www.google-analytics.com/collect?v=1&tid=foobar&cid=foobar&t=pageview&dp=foobar&dt=foobar

Very simple API. If I use HTTP it works beautifully.

If I use HTTPS, I run afoul of Silverlight's cross domain policies. According to the docs, google-analytics.com needs to approve the cross-domain call by hosting either a clientaccesspolicy.xml (Silverlight-specific) or crossdomain.xml (original used by FLASH). Turns out they do host crossdomain.xml, and I can see that Silverlight downloads it (via Fiddler), but apparently Silverlight doesn't like the file's content and doesn't allow HTTPS calls to that domain (System.Security.SecurityException).

So.. at least at the moment, I can't use Google Analytics from Silverlight using HTTPS. Does anyone know a work around for this issue?


Note, I can't just use HTTP, because that causes IE to issue a "Allow Mixed Content" prompt which causes problems for some of our customers. I need to use HTTPS like the rest of our app.


EDIT: OK, I took a totally different approach, using HtmlPage.Window.Invoke to call a 3 line Javascript function to do the asynchronous send rather than using WebClient in the Silverlight code. Works like a champ. Anybody see any potential problems with that?

Mud
  • 28,277
  • 11
  • 59
  • 92
  • did you give it a try using the https like : https://www.google-analytics.com/collect?v=1&tid=foobar&cid=foobar&t=pageview&dp=foobar&dt=foobar – Malcolm Jan 15 '16 at 08:24
  • Yes. That's all I did. I changed the `http` in the URL to `https`. Both URLs work fine if I just copying them into a browser location bar, but via Silverlight the `https` causes it to do a cross-domain check and it fails. – Mud Jan 15 '16 at 08:31

1 Answers1

0

I suspect there may be a way to make this work, because I know google-analytics.com is very cross-domain friendly for exactly this reason.

If you absolutely can't get it to work another option would be to proxy the hits. If you do this, you'll want to make sure to use the ua and uip override fields in the hit you're sending so that they show up in Google Analytics with the IP address and User Agent of the original visitor and not your server.

Here's some more info on using a proxy server with the Measurement Protocol: https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide#using-a-proxy-server

Philip Walton
  • 29,693
  • 16
  • 60
  • 84