Google CSE (Custom Search Engine) custom query parameter shows no result - google-analytics

So I was trying to link Google CSE to Google Analytics. However, the "Search Terms" in the GA shows funny cache link. I actually expect the search queries by the users here.
According to this StackExchange answer, it is because the cached results use the same query parameter used in CSE, which is q.
So I'm thinking of changing the query parameter of the CSE in the control panel. Note: I'm using the "Google hosted" layout.
This works, and now the CSE link uses query as the parameter instead of q. However, there is no result shown. It seems that search results only appear when the parameter is q.
Does anybody know how to make the results come up using custom query parameter name?
At the end of the day, I just want to get the search terms in my Google Analytics.
Edit:
You can try this snippets with CSE that I set up for Reddit.
https://jsfiddle.net/kd4wjfeg/4/
Note that if you change the query to q in the URL, the results will show up. I've set up the CSE settings to use query as parameter name, as shown in screenshot above.

You need to customize the search box with the correct attribute:
https://developers.google.com/custom-search/docs/element#supported_attributes
For your example you need:
<div class="gcse-searchbox" queryParameterName="query">
Along with other attributes

Related

GA Query parameters gone when using PageType?

On a page /user/survey I'm triggering a PageView event with PageType UserSurvey.
In GA I see this page views as follows: /user/survey+UserSurvey
However, users land on this page with different query parameters depending on the campaign they were interested in. For example:
/user/survey/?email_campaign=1
/user/survey/?offline_campaign=1
etc.
I want to see only users that came with email_campaign query parameter. How do I do that?
I can't find these query parameters anywhere in GA even when trying to segment the audience by page URL. Are query parameters gone and all page views will be grouped together when pages with different query parameters are using the same PageType? I can't believe some of the URL data could be gone this way.
I would suggest that you use UTM parameters to segment the audience.
For example:
/user/survey/?utm_medium=email&utm_campaign=campaign1
/user/survey/?utm_medium=offline&cammpaign1

WordPress REST API Global Search (API V2)

I am looking for a way to run a global search query across all or multiple post types using WP REST API.
I am able to search posts using:
http://example.com/wp-json/wp/v2/posts?search=test
In turn I am able to search pages using:
http://example.com/wp-json/wp/v2/pages?search=test
How do I search across both posts and pages? I was able to do this in WP REST API V1 by specifying multiple type[] variables in the query?
This might be a bit late but there is an endpoint for that in the v2-api: /wp-json/wp/v2/search.
You can search for any specific post_type by supplying it via subtype or leave it to the default (any) to search in all post_types.
Edit: Of course you can also specifiy multiple with an array as you did before.
Here are some examples using the REST API search endpoint for searching all content or specific content type(s).
Search For a Term in All Site Content
/wp-json/wp/v2/search/?search=searchterm
Search For a Term and Limit Results to a Custom Post Type
/wp-json/wp/v2/search/?subtype=book&search=searchterm
Search For a Term and Limit Results to multiple Custom Post Types
/wp-json/wp/v2/search/?subtype[]=book&subtype[]=movie&search=searchterm
REST API Search Result Documentation

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.

Can I add Google Tag Manager to two domains, being flexible on the ID?

I have two domains, a .nl and a .be domain. Both have their own Google Analytics IDs. Currently I have the analytic code on the website and, depending on the domain, the correct ID is inserted into the code. The tracking works correctly on both sites.
Now I want to implement the Google Tag Manager, to get more flexibility for Javascript.
The struggle is now how get to the same result, without implementing the Google Tag Manager twice (or more if more domains are added).
How can I achieve this? I tried with the rules in combination with a regex on the {{url}}, but without any success.
The best way if you want to prepare for more domains would be a lookup table macro.
First create a url type macro that return the hostname. Then create a macro of the type lookup table - that is a macro that returns a value based on the value of another macro. It should look something like this ( {{url hostname}} is the macro that holds, well, the hostname) :
Then insert the macro name ( {{Google ID}} in the example in the screenshot) in the "Tracking ID" field in you Google Analytics Tag and it will be set according to the domain name. If you want more domains just add a row to the lookup table.

Are variables passed in a URL tracked by Google Analytics

From what I understand, the data passed in POSTs from a form on a site is not tracked by Google Analytics. What about any variables that get passed in the URL, as in ?value=bla
Does value=bla get stored by GA?
If so, is there a way to not track variable info from the URL?
I am aware of the anonymizeIp for IPs.
GA profile settings have a text field where you can enter query parameters that should be ignored. You can also set up an advanced filter to summarily excludes all query parameters (simply google "exclude query parameters google analytics", there a lot of tutorials on how th do this).

Resources