phpgoogle-analyticsseogoogle-analytics-apiimpressions

how to show Google analytics data impressions/clicks/ctr to my site?


I have a banner and for this i want to show Google analytic data impressions, clicks, ctr to my site, I have Google and didn't find any code to implement this.

This is sample code which i got on Google, but don't know how to use that using.

<a href="#" onClick="_gaq.push(['_trackEvent', 'Videos', 'Play', 'Baby's First     Birthday']);">Play</a>

Thank you.


Solution

  • GA does not usually show impression data, it only counts what happens on your website. You can import impression data from Adwords/GDN via account linking and you can import impression/cost data via data imports; for that to work you should, as noted in the comments, tag your banner with utm parameters which assign values for traffic source/traffic medium and campaign. The impressions/cost data that you upload is associated with the campaign data via the campaign name. You can upload cost data via the interface, but you can also do it programmatically via the API with php or any other language; documentation is here. Once the data is uploaded GA will calculate CTRs and ROI by itself.

    However from your question it looks like you want to send impression directly from your banner. This is not usually done since big advertising campaigns easily produce millions of banner impressions and the hit quota for the analytics account would be exhausted pretty fast. If you still want to do this you can use the measurement protocol. Instead of linking an image for your banner you would use a php script that sends a hit to the GA servers and then displays the image. This is not necessarily useful as it would be quite hard to connect that data to data collected on your website.

    So if you're doing this to optimize banner campaign cost data upload ist the way to go. The API is well documented (and pretty basic, too - assemble your cost data as csv and send it with a post request to the http endpoint) so you should have a look at it (and if necessary come back with specific questions).