How to add search engines like _addOrganic in new analytics.js API? - javascript

for my new site I am using new analytics.js (as suggested by Google instead of ga.js). Works fine, except I don't see any keywords set in Google Analytics used in Google search by my visitors.
Seems strange to me as I would expect, that Google Analytics would recognize it's own search engine by default.
So I have tried to search for a way how to add new organic search in JS on my site as it was possible with ga.js _addOrganic function. But I have found nothing, there is no mention about this possibility for new analytics.js.
Can anybody give me some hints ? Thanks in advance.

This is no longer set in the code but via the admin interface. Go to ->admin->tracking info->organic search sources (see screenshot).

Related

Should I use both gtag.js and GTM?

I´m a bit confused with Google Tag Manager and gtag.js. I have read a lot about it, but It´s not 100% clear to me what to use in my case.
Historically, we have been using gtag.js in our AngularJS webapp. We also used the library angularytics to track Google Ads conversions of purchases providing dynamically prices and leads directly from our website.
We have migrated to GTM to provide third party libraries from the GTM interface. This means that we have commented/removed gtag.js. Now, we track page analytics from GTM. However, obviously, our angularytics calls to Google Ads conversion tracking using gtag.js has stopped working.
At this poing I´m very confused with some questions:
I have read that I can add Google ads conversion tracking using GTM setting up conversions one by one. But, is it possible to set the price of each product which is totally dynamic? Or this case should I use gtag?
Does GTM provide a library to replace gtag functions? From the SEO optimazation point of view, I think would be interesting to avoid loading two libraries gtm and gtag.
Is there any problem that both libraries live together?
Well, you can think of GTM as a service where you can dynamically change the included tags in a website without direct access to the production source code. This is for example widely used for marketing agencies whose clients won't give away access to their servers. But it doesn't really have anything to do with Google Analytics at all as you can insert tags from any service provider (Social pixels, Intercom-like services...)
If you use Google Tag Manager to handle those tags you should remove the script call from your code. Otherwise it will be invoked twice

How to retrieve a "gtag" (Google Tag) from a page?

I am developing a chrome extension that extends the functionality of our company portal. Our company does not own this portal; The portal is maintained and owned by a different company. If we want to change things, we cannot; We must ask said company to implement the change, and its up to them whether they do or not. So like I was saying, the extension does things to improve accessibility and navigation, as well as inserting specific bits of functionality that make it easier to use the website.
I want to make the extension specific to the user type, just like within the portal itself. Within our company portal, we have different roles: agents, admin, brokers, etc. However, there is really only one way for me to detect the type of user: gtag, or a google tag. The portal uses google tags, and I noticed while searching through their html, that there is a google tag for the user type. So my extension could in theory search the html to find the google tag, and extract the value for 'user-type'!
There is a lot of documentation on how to add a google tag to a website, but none to retrieve a google tag. However, I know it is possible. There is an chrome extension (provided by google) called Tag Assistant that does just this. It detects google tags on any page you are on, and then displays them in the extension's pop-out window.
How can I retrieve the 'user-type' value from a google tag on a page?
Here is the code on the page I am looking at:
<script>
gtag('event', 'page_view', {'user-type': 'admin'});
</script>
For this example, I need to extract the 'user-type' value of 'admin'.
I cannot think of anything very ingenious. So far, all I can think of is using jquery and regex patterns to get it. For example, this code accomplishes the task:
$("script:contains('user-type')").text().match(/(?<=('user-type':\s\'))[a-zA-Z]+(?=('))/g)
I guess the I have an answer, but it just is not as elegant as I am thinking it should be.
How you would do it? Or am I overthinking this, and should stick with my current solution?

How to set up a Google Analytics experiment in Meteor

I set up Google Analytics tracking in meteor using the okgrow:analytics package. It works and I get the real time view of pages and events correctly. I want to run an A/B test to compare one of the features of my app. However, I ran into a few problems, mostly stemming from the fact that Meteor creates a SPA:
Google Analytics asks me to insert a script to track the experiment right after the opening head tag on the page I am trying to test. I can do that, but either I will have to put it on the head which is used among all the pages or inject dynamically which causes an error.
It seems that the Google Analytics script is not changing the page correctly. This is probably related to the fact that I can't insert the script into the head correctly, but I was thinking it might also be because it is a single page app and it seems like the script expects a more traditional website.
Also please note that I am using Flow Router.
I have searched without any luck. Does anyone know how to set this up correctly? Any suggestions or ideas would also be welcome.

How can I get a client location using the Google Map (Geocoding) Javascript API using pure javascript?

There are plenty of examples all over the internet, including stakoverflow, of getting location information. But every single one that I find uses HTML to include the library (<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=true"></script>) and display the information. I need to get the client location from a script, not a web page. I just need to get the location information - I don't need to display it. No HTNML - just javascript.
I've tried several of the examples found on this site, but they all use the navigator.geolocation or google.maps classes, neither of which are recognized by Google Scripting. I've tried to include a resource, but maps nor navigator or any of the required APIs are in the list. I've even attempted to find a RESTful way to use the API and get a JSON response; found nothing even close.
The example used in several places is this one on developers.google.com, including several appearances in stackoverflow like this one.
I suppose it could be a very "newbie" issue, but I'm flummoxed!

How to embed or recreate a Google Analytics Graph in a custom CMS

I would like to know how to create a graph with Google Analytics (maybe using the api), but I'm unsure if there is already a plugin or tutorial on how to do this. The Javascript API reference at Google.com sucks.
Also any reference to how to create a line graph (canvas element?) would be great too.
Thanks!
I learned to use the Google Visualization API (the one used by analytics, and the one I believe you refer to) from the examples at https://developers.google.com/chart/interactive/docs and found it quite clear.
You can use examples of different graphs from the Gallery as well: http://code.google.com/apis/visualization/documentation/gallery.html
I created a service specifically for this purpose:
EmbeddedAnalytics
You define your chart type (line, bar, horizontal bar), metrics (pageviews, visits, etc), dimension (date, country,etc), and a time frame. Then you simply embed a snippet of code into your site where you want the chart to appear.
Google now has an article specifically on this topic.
https://developers.google.com/analytics/resources/articles/gdataAnalyticsCharts
Try this:
Google Analytics Easy Dashboard Javascript Library
An easy way to build a custom Google Analytics Dashboard on your own page.
http://analytics-api-samples.googlecode.com/svn/trunk/src/reporting/javascript/ez-ga-dash/docs/user-documentation.html#register
Demo: http://analytics-api-samples.googlecode.com/svn/trunk/src/reporting/javascript/ez-ga-dash/demos/set-demo.html
Here is step-by-step guide how to embed Google Analytics chart into a webpage as interactive widget: http://explainum.blogspot.com/2011/04/how-to-add-google-analytics-chart-to.html
EDIT (5/15/2012): The link above goes to a blog post on Explainum -- 3rd party web-service which allows creating embeddable charts from various data sources including (and most popular) Google Analytics.
Connection to GA is made using OAuth. You will need to know your GA profile ID in order to connect. Data is updated every 2-24 hours. The service is free.
DISCLAIMER: I'm one of Explainum's creators.

Categories