开发者

Track embedded charts via Google Analytics

开发者 https://www.devze.com 2023-02-11 06:47 出处:网络
I\'ve got a site which produces charts such as the one below I\'d like to encourage visitors to embed the generated graphic on their own sites and blogs. Is it possible to include views for that ch

I've got a site which produces charts such as the one below

Track embedded charts via Google Analytics

I'd like to encourage visitors to embed the generated graphic on their own sites and blogs. Is it possible to include views for that chart in开发者_如何学Go google Analytics? I want to be able to see when a site embeds the image so that it's tracked in the analytics reports.

I'd envision some API that I can call from the server-side method which generates the PNG, but haven't been able to find anything specific.

Thanks!


This is indeed possible, have a look at the Google Analytics for Mobile Websites documentation. This details how to build a request to google analytics on the server, with quite a few different code samples (C# included).

While this documentation revolves around tracking page views, this concept could be extended to other types of activity you can record in google analytics, such as Events. In your specific situation I think I would want to setup the view of the chart as an Event, as this will not 'mess up' your true traffic (though you could use an advanced segment to exclude the chart traffic if you chose to register them as page views).

The documentation for event tracking is available here. Looking through it should give you a good idea of how you could express viewing your charts. Once you got an idea of how you wanted to track the event in GA, write the javascript and then view the URL (beacon) it generates to send the information to google. You'll be able to use that as a template to send event information from the server.

In regards to actually serving the image, you have a lot of options. If you app is written in MVC, look at the FileResult class (and the asssociated File() method available on the Controller class). If you working in a Webforms app, you will be using a Response.WriteFile() or something to that affect. This wrox article has an example of the idea behind this. The example is for creating a no leaching / hotlinking image handler, but the concept of writing an image to the HttpReponse is the same.

0

精彩评论

暂无评论...
验证码 换一张
取 消