Canonical way to disable analytics in flutter debug build - firebase

I have a flutter app using firebase and google analytics. My data about active users is wrong as I am testing a lot in emulators and google analytics thinks that the installs there are real users. As I often reinstall the app for testing it somehow seems to count it as a new user every time.
As a solution, I'd like to disable google analytics when building the app in debug mode and only activate it when I build it with --release.
Does anyone know how do achieve this with a flutter app?

I assume you're using Firebase Analytics in Flutter (I don't think there's GA for Flutter). You can use kReleaseMode flag when setting navigatorObservers of MaterialApp and creating FirebaseAnalyticsObserver instance. Here's how I do it in my app (notice that I also use preferences which allow user to turn on/off analytics, as well as desktop platforms where there's no Firebase support which is why I specifically check for Web, iOS and Android platforms):
MaterialApp(
...
navigatorObservers: preferences.isAnalyticsEnabled &&
kReleaseMode &&
(kIsWeb || Platform.isAndroid || Platform.isIOS)
? [
FirebaseAnalyticsObserver(analytics: FirebaseAnalytics()),
]
: [],
...

Maybe not what you are looking for, but you can remove all the ip-addresses of your debug devices from getting tracked in Google Analytics.
UPDATE: the original answer was for Universal Analytics only. Updated the answer to also include Google Analytics 4 properties.
For the old Universal Analytics properties, the instructions according to this page are:
Exclude Your IP Address From Google Analytics
Login to Google Analytics and select your profile
Select the Admin menu
Under Account select All Filters
Click Add Filter
Give the filter a name (can be anything, I use the IP address)
Leave Filter Type as predefined
It should read: Exclude + traffic from the IP addresses + that are equal to
Enter your IP address
For the new Google Analytics 4 properties, you can filter out "internal traffic" by following the instructions on this page:
In Admin, click Data Streams in the Property column.
Click Web and then click a web data stream.
In the web stream details, click Configure tag settings (at the bottom).
Click Define internal traffic.
Click Create.
Enter a name for the rule.
traffic_type is the only event parameter for which you can define a value. internal is the default value, but you can enter a new value (e.g., emea_headquarters) to represent a location from which internal traffic originates.
Under IP address > Match type, select one of the operators (e.g., IP address equals).
Under IP address, enter an address or range of addresses that identify traffic from the location you identified in Step 8. You can enter IPv4 or IPv6 addresses.
Click Create
Note: before step 4 you might need to first click on "Show more" to see the "Define internal traffic" button.

Check this out from another answer. To disable the collection of data by Firebase Analytics in your app, see the instructions here.
In summary, to disable temporarily, set FIREBASE_ANALYTICS_COLLECTION_ENABLED to NO in the GoogleServices-Info.plist file. To disable permanently, set FIREBASE_ANALYTICS_COLLECTION_DEACTIVATED to YES in the same plist file.
https://stackoverflow.com/questions/37518212/how-to-disable-remove-firebaseanalytics#:~:text=To%20disable%20the%20collection%20of,in%20the%20same%20plist%20file.

Related

Firebase Remote Config - Conditions not applied

I am using the Firebase Web SDK 8.3.1 and I have created a remote config parameter with conditions based on a custom user properties.
The problem I encounter is that my end users always get the default value, never one from any of the conditions, even if I am sure the user actually matches the conditions...
I see in the doc:
Warning: To use audiences and user properties with Remote Config, you
must enable Google Analytics data sharing for your project. In your
app, you'll need to ensure Firebase Analytics is present and data
collection is available as well.
Then if I follow the provided link I see the instructions:
To manage Google Analytics for Firebase data sharing:
Sign in to Firebase and select a project.
Click the Settings icon and select Project Settings.
On the Project Settings page, click Data privacy.
See the options available under Google Analytics data
sharing. When you share Analytics data, you share it for all the apps
in your project.
Turn on the switch for Share Analytics data with all Firebase
features, including Predictions, A/B Testing, Remote Config, and
Notifications (this is your default setting) to enable all current
options to share data with Firebase features.
But in my firebase console I dont have this switch! Under "Google Analytics data sharing" there is now another link:
So I cant turn on this setting :(
Note: how I made sure my user actually matches the condition "user property X == A":
Wait 30mins
Launch the app with a user having user property X set to A
Launch the Realtime dashboard of Firebase Analytics and filter to the last 30mins
And here I see that there were indeed 1 user in the last 30mins and this user had property X set to A
So is there anything special I should do when I want to create a condition using custom user properties?

Google Analytics - View filter not working

I have a Google Analytics account for a mobile app (it is actually a .NET Desktop application that is hooked up to the API for mobile apps).
To get rid of referral spam etc, I've set up an include-filter for my view (see pic below). The filter checks the Application Name field and should include only traffic that has this field. In my application, I always call the GA API with this application name.
Now, the problem is that this filter seems to not work when set as a View Filter (to filter out incoming traffic). Even though I set this filter up several weeks ago, I still get referral spam traffic that does not have a valid Application Name. But if I apply the exact same filter to my reports, it actually filters out the spam.
Does anyone here have an idea of why the filter works when filtering out reports, but not as a view filter?
I solved this by including a hostname filter. The filter is set as:
Include -> Hostname -> Filter Pattern "(not set)".

Partial IP Anonymization using DTM

Is there a way to anonymize IP based on the URL address. The site runs across many countries, and we need to anonymize the IPs for the traffic coming from a specific country only. The subdomains are different based on the countries.
My analytics setup utilizes DTM (Dynamic Tag manager) and is configured to send data to GA (Google Analytics)
You should be able to use the "Customize Page Code" field - test the url if your user comes from a domain that requires anonymization and if so set a call to anonymizeip.
if(location.hostname.indexOf('some_site.de') > -1) {
ga('set' 'anonymizeip' true);
}
Since the custom code is run before the first pageview this should work to anonymize the IP for that domain. I admit I haven't tested this, but you can look into the network tab, if the call to the Google servers contains the parameter "&aip" then the IP is anonymized.
Here is a pirated screenshot from the Adobe documentation to show where the Customize Page Code field is (bottom of the image). Hit the "open Editor" field to insert your code.

Can a private IP address change?

Okay, this may be a stupid question. I have setuped a Google Analytics account to analyze the traffic of my own site (online portfolio).
My question is: How can I exclude the traffic from me?
Can I just simply get my public IP address and exclude it? Will it change?
If it will, how can I effectively exclude the internal traffic? Many thanks!!!
Just set up Ghostery plugin on your main browser and use only this browser for working with Your site.
Simple and very effective.
Yes, your IP address is likely to change over time.
IP filtering is best used for corporate networks, which have static IP addresses (or range of IP addresses). IP filtering is unlikely to be useful for individuals.
The best way to filter out your own traffic would be to create a Custom Dimension for User Type, and have your CMS/Portfolio application fill out its value depending on visitor's log-in status.
1. Create a Custom Dimension in Google Analytics
Navigate to the Admin Section of Analytics, and create a new Custom Dimension for User Type.
For reference and/or more details, see the official Google
documentation about creating Custom
Dimensions.
2. Create filtered Views in Analytics
Still in Google Analytics, you can set up multiple Views and use filters to remove yourself from the traffic logged.
For example:
Leave the default View provided as a "Raw & Unfiltered View".
Create a new View, "Visitors only", and apply an "Exclude Filter" based on your Custom Dimension, preventing "Administrator" hits from being displayed.
For reference and/or more details, see the official Google
documentation about creating a
View and
managing View
filters.
3. Have your CMS/Portfolio print the user status for each view
For example:
When User is logged in as Administrator/Contributor, have the application output:
ga('set', 'dimension1', 'Administrator');
When User is anonymous, have the application output:
ga('set', 'dimension1', 'Visitor');
Unfortunately, you might have to look for plugins and/or do code it yourself, depending on your application.

Same Analyics Account ID on multiple website

I am using Asynchronous google Analytics code in my website. Account key for Google Analytic which i am using for Live website in also in my local website environment.
but in my google analytics account the Url is of live website. suddenly i noticed that my Google Analytics is tracking the data from local environment as well and that is a huge huge problem. why its tracking from two different URLs.
Google Analytics will track any domain or URL onto which you have installed the Google Analytics Tracking Code (GATC). For analytics/tracking purposes, it does not matter to Google which URL you written your GA account, either at Admin -> Profile Settings or at Account List -> Account Settings.
For example, let's say that your current GA account number is "UA-12345678-1". You have installed your GATC with UA-12345678-1 onto "livewebsite.com" and onto "localenvironment.com". As long as the GA JavaScript file called "ga.js" can load and can connect to the Internet, then a GA cookie can be created and stored on your browser and the tracking information can be sent back to GA.
Assuming that you want to keep GATC installed on your local environment webpages, some possible solutions that may fix your dilemma would either be to create a filter to exclude your own traffic or install an entirely new, unique account number into your local environment:
'1. Exclude your own traffic from UA-12345678-1 by creating a new profile for UA-12345678-1. In the new profile, create and apply one of the following "Custom/Advanced" filters:
'a. "Include" traffic from "Hostname" of livewebsite.com
--or--
'b. "Exclude" traffic from "Hostname" of localenvironment.com
--or--
'c. "Exclude" traffic from "IP Address" of your local environment. For example, if your local environment uses the IP address 65.99.208.1, you would write the IP address into the Exclude IP Address advanced filter as: ^65.99.208.1$
More info here:
http://www.morevisibility.com/analyticsblog/clean-up-your-google-analytics-data-with-these-5-filters.html
'2. Create a second GA account (they're free to create):
'd. Install the new GA account number into the code of localenvironment.com. After installing the new GA account number (for example: UA-98765432-1) , you would continue using UA-12345678-1 on livewebsite.com without interference from your test environment, which would use UA-98765432-1 .

Resources