Search code examples
iosgoogle-analyticsspam-preventionviewwillappear

How to prevent ios spamming produced on Google Analytics report by quickly switching views?


Currently I put the tracking code in viewWillAppear for tracking page views. I found out that if I quickly switch views back and forth without contents being fully loaded, the tracker still sends the traffic as many times as the number of view switches. Can I prevent this kind of spam on my analytics report? Where is the best place to put the tracking code for tracking iPhone's page views.


Solution

  • Set the Sampling Rate: You can set the sample rate using the property sampleRate. If your application generates a lot of Analytics traffic, setting the sample rate may prevent your reports from being generated using sampled data. Sampling occurs consistently across unique visitors, so there is integrity in trending and reporting when sample rate is enabled. The sampleRate parameter is an NSUInteger and can have value between 0 and 100, inclusive. Here is an example that turns the sampleRate down to 95%:

    [[GANTracker sharedTracker] setSampleRate:95];
    

    A rate of 0 turns off hit generation, while a rate of 100 sends all data to Google Analytics. It's best to set sampleRate prior to calling any tracking methods. You can learn more about sampling from the Sampling Concepts Guide.

    From: http://code.google.com/mobile/analytics/docs/iphone/#overview