Send custom data to google analytics from server side - google-analytics

I want to send these information title, target amount, category, account name to GA for every user who creates a page in our website. And if anyone make transaction on that page I want to generate a revenue of 5% based on the transaction amount for every transaction. I've no clue how to do that.
So far what I've achieved is I set up the service account by following this link and create a custom dimension. Playing with the code snippet I can update the name of the dimension and other things but not sure how to send an object value with all the fields that I need in this custom dimension. My question is if I call this again will it update and replace the old value with the new value? I don't want that. Every time I want to insert a new value in the old value. Shall I need another dimension and what if I want to relate this custom dimension data to ecommerce later on. How can I do that?
try:
analytics.management().customDimensions().update(
accountId='123456',
webPropertyId='UA-123456-1',
customDimensionId='ga:dimension2',
body={
'name': 'Campaign Group',
'scope': 'SESSION',
'active': True
}
).execute()
Can someone please suggest me what should I do here.

you use the measurement protocol to send data to google analytics. The google analytics management api is only for managing your google analytics account.
POST /collect HTTP/1.1
Host: www.google-analytics.com
payload_data

This article should help you achieve what you want.
Basically the custom dimensions in your url should be like cd1, cd2 so on...
https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters?hl=en#customs
Here is a code sample that might help
https://www.simoahava.com/analytics/13-useful-custom-dimensions-for-google-analytics/#23-payload-length

Related

Can't use user id in Google Analytics

We have been registering user ids, and when we go to Audience->User Explorer, the users are all there, each with their activity measures. But we can't find a way to filter some users out of our custom reports.
We do ga('set', 'userId', 'xxxx-xxxx'); but we didn't create any custom dimension. We just told GA specific user-IDs for each.
We haven't been able to set up a segment, as we can't find the id in the filter. Neither in report filter.
We could go the the user and delete all their data. But that is not our point, and we need to keep this data as well. Ideally we would segment our users, but we can't use this filter in the segment definition.
If you want to segment user by userID, you need to create a custom dimension of which you can access. The clientId is not accessible as a dimension to segment on.

How to track USER_ID generated by Google analytics which came from certain campaign/utm?

when somebody register on my website, Google Analytics genrate a new USER ID form him. How can I label/track generated USER_IDs which came from certain campaign (i.e. form certain custom URL with utm parameters)?
Thx for help.
In the first step you should push the UID (or CID) as a Dimension into your GA Account. So you are able to export the UID/CID through the API (or CSV). Here is a article how to do this: https://productforums.google.com/forum/#!topic/tag-manager/lcTvzfvcTvU;context-place=topicsearchin/tag-manager/category$3Aadvanced-setup--implementation%7Csort:relevance%7Cspell:false
If you have the ID as a Dimension you can build a Segment containing your Campaign. In your reports you now see the IDs.
Another solution would be to fire the dimension with the IDs just if a User is on a page containing the specific parameters.

reporting on event hits in google analytics

I have been tasked with using Google Analytics to report of use of a desktop app so we can see which parts of the program are being used and how heavily, and potentially also see which companies are using which parts of the program (each company has a unique companyID). Ideally I'd like to be able to look at correlations (e.g., How many users who use report A also use process B?)
I currently have my program set to fire off a call to analytics. I've set it up to use the event tracking, but I'm open to app/screen tracking or something else if something would work better. I'm passing values like
v=1
&t=event // Event hit type
&tid=UA-XXXXX-Y // our ID; real code has valid value here
&cid=12345 // CustomerID
&ec=JobFinancialReport // Event Category
&ea=Run // Event Action
&el=Manager // Event label
&ev=7 // Event value
What I can't figure out is how in Google Analytics to set up reports that would show me something like:
CustomerID Category Label Total Hits Unique Users
12345 JobFinancialReport Manager 27 2
12345 MarketingReport1 Manager 6 4
I'm totally new to analytics so pardon my ignorance if I have some key misconception here. I've searched Googles sites and other questions here, but I may be wording my question incorrectly so I'm not finding something that's there. This is only one example; in some cases we might want to see how broadly each customer is using the program; in other cases we'd want to take the customerID out and just see how much a particular report is being used overall. Appreciate any guidance. Thanks.
The "cid" parameter is the client id, the value that is used to stitch single interactions into sessions and users.
The first problem that comes to mind with your setup is that the client id is not exposed in the user interface (with the single exception of the user explorer report) or the API.
You would need to implement this via a custom dimension (probably user scope, since it probably will never change for a given user) where you pass in the client id (you still need the cid parameter).
Then you could create a custom report (or create a report in Google Data Studio) with the custom value as primary dimension and your selected metric.
If you want to report "Unique Users" you would probably need to create a cid per logged-in user (if all users of the app have the same cid then you will always have but a single user reported). You should then probably create a second custom dimension for the company id, so you can segment your reports by company.
you can use custom reports in google analytics to get your desired output. here is how to create custom reports https://support.google.com/analytics/answer/1151300?hl=en

Using Google Analytics how can I track different audience segments viewing the same page?

I'm looking for some general advice. The site I'm currently working on is full of duplicate content that's about to be deduplicated. But it was built that way to track different audiences visiting the pages by reporting on the URL hits.
Current Links
www.MySite.com/homeowner/painting
www.MySite.com/professional/painting
www.MySite.com/designer/painting
My concern is that at the end of the day, the person managing the analytics wants to be able to look at their report and say "We had X number of professionals visit the site." Simply deduping will elimate that.
I'm thinking Google Analytics might have a way to pass audience/tags in via the URL like this:
Example Links with Tracking
www.MySite.com/painting?tag=homeowner
www.MySite.com/painting?tag=professional
www.MySite.com/painting?tag=designer
Is this possible with Google Analytics? Does anyone have an example website using this?
I've looked into Custom Dimensions and Metrics but they seem to be overkill https://developers.google.com/analytics/devguides/collection/analyticsjs/custom-dims-mets
Custom Dimensions are not overkill, it's a reasonable idea for you to use them (because segmentation is what they are for, really).
Using a url tag has a couple of disadvantages. For one The tagged pages will appear as three distinct rows in your reports - you will be unable to get an aggregated number for www.MySite.com/painting, instead you will have three Urls (or as many as you have parameters).
Secondly, homeowner etc. are attributes that belong to a session, or even a user (if the role cannot change from visit to visit). However if you track them via url parameters they have only a hit level scope, i.e. they are recorded as a property of the viewed page, not the viewing visitor. If you record this as a session scoped variabe you need to set it only at the first pageview, and the value will be applied to all subsequent pageviews for that session.
So an easy way (example assumes you are using php) might be to use
if(isset($_GET['tag']) {
ga('send', 'pageview', {
'dimension1': "<?php echo filter_input(INPUT_GET, 'tag', FILTER_SANITIZE_ENCODED); ?>"
});
} else {
ga('send', 'pageview');
}
in your tracking code after you have created a session scoped custom dimension in your property settings ("dimension1" referring to the first custom dimension in your account, the numeric index changes for each dimension. The dimension name is only used in the reports, not the tracking code). You need to be careful not to send an empty value when the query string is not present - a session scoped custom dimension only records the last value from a session, if you send empty values you overwrite the value you recorded at the first pageview.
Alternatively you can do this without changing the tracking code at all - create a custom advanced filter to capture the value from the query string, a second to copy the value to your custom dimension and a third to remove the query string from the url. However while that's a neat trick using code is much easier.

Google Analytics "to use this feature visit: Event-Tracking.com"

Why am I seeing "to use this feature visit: Event-Tracking.com" along with my other Event tracking data? I searched the web but found no answers. What is it and why is it there? Using Universal(latest). Example event tracking for a download:
onclick="ga('send', 'event', 'Baseball', 'Download', '1977');"
I see analytic data for the above, but can't figure out why the "to use this feature visit: Event-Tracking.com" is posted too.
Eike's comment is the answer. Here is how to set the event filter.
In Google Analytics click Admin and then under the View column find Filters.
Add a new filter with Custom type.
Choose Exclude and in the option type "event" and select Event Category.
Paste in whatever garbage the spammers filled your account with.
Verify the filter to see if there are matches on your data set before saving the new filter. Note that any filters permanently delete the GA data from the account. Changes from applying a filter cannot be reversed.

Resources