Accessing User ID as a variable in Google Tag Manager for mobile - firebase

I'm getting started with Google Tag Manager for Android/iOS, and can't find a way to access the User ID as a variable. I can access Firebase User Properties and Event Parameters just fine.
So far, I've tried setting it using FirebaseAnalytics.setUserId and trying to access it as a User Property called user_id / userId.
Some workarounds I've thought of:
Using a CustomVariableProvider (preferred)
Setting the User ID as an Event Parameter (this wouldn't work with built-in events)
I'm just trying to make sure there's no built-in way of doing this before I resort to workarounds. Thanks!
I was not able to find the User ID (or UID) in the list of built-in variables, see this screenshot

There is a built-in way, but it requires quite a sophisticated setup.
In GA version 4 the path is changed comparing to the previous version, where the same could be done much easier via "Tracking Info".
Here are the starting steps in GA4:
Open https://analytics.google.com/analytics/web
Bottom-left corner -> Admin -> Setup Assistant -> Advanced setup -> User ID
Follow the instruction
After that UserID will be available in GTM.
Video guide for exact steps: https://www.youtube.com/watch?v=TVJMFVOXFUQ

Related

GA4 dimension "Signed in with user ID" disabled

After configure the google analytics property using GA4 instead of UA, I've seen there is something wrong with the user Id dimension.
As you can see in the following image seems like GA4 is not receiving data with the user_id property so it is unable to filter by the property.
By the way I'm referring to this property I'm using a Reporting identity option called By User-ID and device.
Seems like I have something wrong on my configuration, however when I use the DebugView tool of GA4 I can see the user_id is properly sent:
So I'm not sure what's going on here.
Why is Signed in with user ID dimension disabled?
One day after "Signed in with user ID" is enabled without any additional configuration change. So it seems like it just needed some time to fit with data I guess.

Two wordpress database with same users

I want to have the same WordPress users in two different databases
For example, if a user registers on SiteA, then he can login to SiteB. And reverse.
Also i want create same cookie for both after login.
mywebsite.com/ (SiteA_DB)
mywebsite.com/blog/ (SiteB_DB)
I've never done this before and maybe Wordpress has hooks to archive this, but I prefer using mysql for such a trick.
You could try ..
.. using 'federated storage' ( https://stackoverflow.com/a/24532395/10362812 )This is my favorite, because you don't even have to share a database or even the mysql serverThe downside is, that it doesn't work with db cache and uses an additional connection.
.. creating a 'view' ( https://stackoverflow.com/a/1890165/10362812 )This should be possible when using the database-name in the query itself and it would be the simplest solution if it works. Downside: The 2 tables have to share the same mysql-server and have to be assigned to the same user as far as I know.
-- **Backup your database before trying!** --
DROP TABLE `second_database`.`wp_users`;
DROP TABLE `second_database`.`wp_usermeta`;
CREATE VIEW `second_database`.`wp_users` AS SELECT * FROM `first_database`.`wp_users`;
CREATE VIEW `second_database`.`wp_usermeta` AS SELECT * FROM `first_database`.`wp_usermeta`;
This should work, according to: Creating view across different databases
.. creating a 'shadow copy' ( https://stackoverflow.com/a/1890166/10362812 )Works with caching and is a standalone tableDownsides as 2. solution + a bit of setup and I think it might be the worst option in performance
This were answers to this question: How do I create a table alias in MySQL
I merged them together for you and made them fit your use-case.
Please also notice, that solution 1 and 2 will replace your current user-tables auf "second_database" because you write directly into "first_database" when querying the fed. storage or the view. This can lead to problems with user-role plugins. You should take care of syncing the plugin-options too, if you should use one of them and in case it uses different tables or 'wp_options' values.
Let me know if this works, I have to do a similar task next week. While researching I found the linked answers.
EDIT: I was missing the point of "cookie-sharing" in my answer. Your example shows a blog on the same domain - you should be able to change the way wordpress sets its cookies to be domain-wide. What I did once for 2 different domains was, that I hooked into the backend (is_admin) and added a javascript which did a post-request to siteB, receiving a token which is stored but marked as 'invalid' on siteB. This token then was passed back to my plugin on siteA which checked if the user is logged_in and (in my case) have adminrights (current_user_can()) and if so, it was sending this token back to sideB which was marking this token as valid to login. (Make sure only sideA can tell sideB to make this token valid!) Once a user is seen with this token in a cookie on siteB, the user is logged-in automatically in the background. Also I made this bidirectional. I am sorry, that I can't share the code for you. I don't have access to it anymore.
Greetings, Eric!

Google analytics user explorer get user report

How do I get user report from user explorer, using GA API. Didn't manage to find any information about it here https://developers.google.com/analytics/. For instance in user explorer (audiences section) you can see a list of records having ids like 11111111111.2222222222 and I want to get information about user activity on the website for record with id 11111111111.2222222222 using GA API
While the latest GA release notes says the client ids have been "surfaced" (i.e. made visible) it is (at least currently) not available as a dimension via the API. So if you want to use it you'd have to add the client id as a custom dimension to your reports yourself. Off the top of my hat this should look something like this:
ga(function() {
var trackers = ga.getAll();
trackers.forEach(function(tracker) {
tracker.set('dimension1',tracker.get('clientId'));
});
});
Put before the pageview this would write the client id to your custom dimension with the index 1 (which you need to create in advance via the interface in properties->custom definitions). Should also work with multiple trackers on the same page.
This will of course not help you with data that's already been collected.

How to Track Store Locator Search terms in Google Universal Analytics

I am in the process of setting up enhanced Ecommerce for GA and have had a few requests of additional of what else the client would like to see in their reports. Once of which is
"Where can i see a report if the locations that a use types in when they use the store locator"
There is already an internal search functionality thats been set up and is tracking the search terms people are typing when looking for products, but i'm not sure if i would need to set this up as a second search terms report or if it's something different?
The URL of the page is different to the internal search results and is www.domain.com/store-locator#wales|GB|0|0|0
Any insight into this would be really helpful.
Thanks,
Roxi
As to me knowledge, you are not able to use bookmarks (#something) in GA for internal site search setup. Only GET and POST parameters are allowed. In your situation I think the best solution is to use GA events to send the data about used location each time the user is using this functionality. You need to include addition ga() function call to track those events. Info about how to set it up you could find here: event tracking. After setting things up, you will see all the info about number and type of called events in Behavior -> Events reports section in GA.
Example code:
<button onlick="var hash_location=window.location.hash;ga('send','event','Locator',has_location)">Click me</button>
With such function new event will be send to GA with Event Category=Locator and Event Action=hash in the url. You have some complicated hash, so most probably you need to extract first some info from this using regular expression. Example to get first item from |-separated list in the hash:
var pattern = new RegExp('[^#|]+');
var hash_location = pattern.exec(window.location.hash)[0];

Measuring goals for users who have never logged into my site before

I have a web app. The home page has two main actions:
Sign up to the application
Log into the application
I have a goal set up for sign-ups. I am trying to track the goal conversion rate of users who have never logged into the application before.
The problem I have at the moment is that the conversion rate is being skewed by users who are visiting the homepage simply to log in.
Is there a simple way of doing this?
Thanks very much,
Ben
For the kind of tracking you are looking for, there should be some coding on both your system and Google Analytics.
First, I would recommend you place into your system the intelligence to know the number of log-ins the user has made (As an example, a counter on your database).
Now, to implement that, you will need to set a Custom Var in Google Analytics in a visit level, to segment the users from the non-users, in that CustomVar, you can store both the user ID and the number of logins he has made.
This is the on the login page:
Your Code Should Look Like:
_gaq.push(['_setCustomVar',
1,
'Member Login',
'NUMBER OF LOGINS', // SET THIS FROM YOUR SYSTEM
2 //VISIT LEVEL Custom Var
]);
Remember that this code should go before tracking the pageview.
After setting this up, you should use Advanced Segments to check those specific users, one case could be: (Using the example above)
Setup an Advanced Segment that "Excludes" the Custom Variable (Key 1) - Mathing RegExp : .*
This will give you all the never-loged user access.
Something else you could do is set up Adv Segments to check on a specific number of logins
Setup an Advanced Segment that "Excludes" the Custom Variable (Key 1) - Mathing RegExp : [^1]
This will give you all the users that loged-in more than once.
You can find more info on Custom Vars here.

Resources