Google analytics Site search is not working as expected - search

I just started using Google analytics for my website. I found that, enabling site search for a site is very easy as mentioned below,
But my site doesn't have the search term in the query string, instead it is part of the url as mentioned below,
https://mydomian.net/search#q=boxtest18
for some internal reason i cannot modify the code to append search term as querystring to url.
This article explained how to configure site search in GA, if Site Search Term Is Present in the URL: NOT As Query Parameter (Single Term).
When i tried, it doesn't seem working.
Below is my filter configuration.
What i'm doing wrong here?
Can i use the filter for this kind of url?
Is my regular expression correct?
Help me out here.

As Michele mentioned you may append the hash when the query is visible in url hash;
gtag('config', 'GA_TRACKING_ID', {
'page_path': location.pathname + location.hash
});
though if you are using requests (ajax or any restful api) you should manually trigger a page view as a virtual page.
pagePath = location.pathname
gtag('config', 'GA_TRACKING_ID', {page_path: pagePath + '?gender=' + request.gender });
// or if using analytics.js
ga('send', 'pageview', pagePath + '?gender=' + request.gender);
For more info, here is the help section for sending posts
https://support.google.com/analytics/answer/1012264?hl=en#Post
Pageview Request Object
You may use these to manually trigger a page view for a virtual page. If you are looking to use analytics.js (ga()) please refer to this documentation
gtag('config', 'GA_MEASUREMENT_ID', {
'page_title' : 'homepage',
'page_path': '/home'
});
Parameter name Value type Required Description
page_title string No The page's title.
page_location string No The page's URL.
page_path string No The path portion of location. This value
must start with a slash (/) character.
For more info, here is the official documentation
https://developers.google.com/analytics/devguides/collection/gtagjs/pages
Event Request Object
I am adding this section for completeness
You may use these to trigger a tracking event. If you are looking to use analytics.js (ga()) please refer to this documentation
gtag('event', <action>, {
'event_category': <category>,
'event_label': <label>,
'value': <value>
});
action is the string that will appear as the event action in Google Analytics Event reports.
category is the string that will appear as the event category.
label (optional) is the string that will appear as the event label.
value (optional) is a non-negative integer that will appear as the event value.
For more info, here is the official documentation
https://developers.google.com/analytics/devguides/collection/gtagjs/events

In Google Analytics the URL paths that are passed to GA with your Pageview hits are stripped of these fragments.
You can update the data before sending it to Analytics (track pageviews).
gtag('config', 'GA_TRACKING_ID', {
'page_path': location.pathname + location.hash
});
Or you can use Google Tag Manager to get the fragment, more info here: https://www.simoahava.com/gtm-tips/track-url-fragments-as-pageviews/
Then you can handle it as you like or replace the # to the ? with a filter.

After digging into Google analytics and Google tag manager i found the solution. Solution was very easy in my case.
For every search, search term was updating in the url fragment. In the below case, i searched for boxtest18 and url updated like below.
https://mydomian.net/search#q=boxtest18
For this, i had crerated a Tag in Google tag manager and triggered it on history change event. That resovled my problem.
Here are the steps.
In google tag manager i have added new tag and filled highlighted info.
Fragment value is a variable which i created.
For the new tag i have created the triggering event as shown below.
And make sure you have the tracking code script and Google tag manager script in your web page. That's it. Hope it helps someone.

Related

Reading a NetSuite Item Fulfillment's shipcarrier field using suitescript 2.x

I have a script which loads an item fulfillment record and from there I am trying to read the "shipcarrier" field. This is a field that is shown on the IF page and if I put the &xml=t in the browser URL I can also see the value (such as Fed Ex or whatever). The issue is, I am struggling with how to get that with the script I am writing. I have noticed it does not appear to be in the schema browser but given that the UI shows it (and the help text shows 'shipcarrier'. I would think there is some kind of way to read it even if it is not as simple as using getText() on the fulfillment record. I have also seen some mention on other posts about it being set but again I don't seem to be able to read it and also .getFields() does not give it back either.
You can get that value using the search module and the lookupfields method.
var fieldLookUp = search.lookupFields({
type: search.Type.ITEM_FULFILLMENT,
id: param_itemful_id,
columns: ['shipcarrier']
});

ViewPath query parameter in SharePoint list causes CSOM to fail Lists.GetById

It seems due to a recent SharePoint Online update that their lists (when selected using the left navigation) now adds a ViewPath query parameter by default. With this change, it seems like the Provider Hosted App redirect now sends a different ListId and not the Id for the actual list. When I use CSOM to resolve the ListId it results in a "Site Pages" and not the list at all.
clientContext.Web.Lists.GetById(ListId);
This code base did work before the recent SharePoint Online update but now I cannot call my list. If I manually remove the ViewPath query parameter from the list then the redirect shows the correct ListId and CSOM resolves the correct List. The problem is I cannot expect users to manually remove that query parameter.
If I navigate to the list by using the Site Content page and not the left navigation then this query parameter is not present and my application works.
Does anyone have context or direction into how to handle this new change?
I have a similar issue on our site. Instead of modifying the list, a script web part on the initial page seems to bleed through. I have ammended the links in the lefthand nav bar in an attempt to circumvent the viewpath query being added. I put in 2 url carriage returns on the end of the link. So far so good for me.

How does a Gmail message Id or ThreadId map to the new Gmail UI?

Edit: addressing the first comment below and for clarity, this isn't a code question. The question is simply:
What do I put into the URI querystring of the new Gmail UI to view a draft message created by the Gmail API?
Despite this not really being a code question, I'm asking on Stack Overflow as it's Google's preferred platform for Gmail API questions.
--
If I view a draft message in the new Gmail UI, the URI is something like this:
https://mail.google.com/mail/u/1/?zx=iij9apqgzdf4#drafts?compose=jrjtXSqXwlFGnSGCQgDCdnHGVFdlpFMgzsCNgpQstQLxdLCMkjKstBmWZkCmjhWTQnpsZCJF
I can't see any way to create such a link from the Id or ThreadId of a message created via the Gmail API.
Previously, one could do this:
https://mail.google.com/mail/u/1/?zx=ov61dxfbrcga#drafts?compose=1631caae9dbb074d
where the value of "compose" is the Id.
How can the same thing be accomplished in the new UI?
I've been encountering the same problem and have had some success in this problem, as well as some issues I still can't get past.
Good news: The new compose parameter format is some kind of "base40" encoding. I searched the Gmail source for a restricted alphabet string, and found and deobfuscated the bit of code doing this encoding/decoding: https://gist.github.com/danrouse/52212f0de2fbfe33cfc56583f20ccb74
This code includes an encode and decode function which should work for Gmail-format query parameters.
Bad news: The values that it is encoding to open draft emails do not appear to be available using the Gmail API. Specifically, they look like this:
thread-f:NEW_THREAD_ID+msg-a:DRAFT_ID -- while the draft ID is the same as it was before, the Thread ID does not appear to match any of the IDs that the Gmail API returns.
Interestingly, if you inspect the subject row in the Gmail UI, it has dataset attributes including all of both the old format and new format IDs - but it's still unclear how to get the new ones programatically.
Thanks to #frank-szilinski - he pointed out that the old format is now translated. I.e. this now works again:
https://mail.google.com/mail/ca/u/1/#drafts/1661237c4db71ace
It doesn't seem to work when the Gmail tab isn't already open, however.
Building on #kremonte gist, and #chris-wood comments, I made a rails gem that correctly creates the open-the-draft-inside-gmail URL.
It's here - https://github.com/GoodMeasuresLLC/gmail_compose_encoder
It's for the use case of "my code created a draft (prepopulated with some text, of course) and now I want to open the draft in compose mode so that my user can review it before hitting "send".
How to get the URL for a draft
If, for example you use a list request from which you get your draft objects:
{
"id": string,
"message": {
object (Message)
}
}
You can take this id and put it into a URL in this format:
mail.google.com/mail/#inbox?compose=[id]
Eg.
mail.google.com/mail/#inbox?compose=3doinm3d08932d
This will open up GMail with the relevant draft open.
I was struggling because I wanted it to work with multiple accounts. However the authuser parameter did not help.
Inserting the email address instead of the integer after the u/ component solved the problem.
https://mail.google.com/mail/u/{email_address}/#drafts?compose={message_id}
The message id is the one provided by the API.

How to get keyword type (Organic or Paid) from Google Analytics Reporting API

I am using Google Analytics Core Reporting API. I have a little confusion that I want to discuss.
First I want to get keyword which User has searched to reach on my site. I have used ga:keyword. I have also seen one other dimension which is ga:searchKeyword. Which one of these will give me desire result?
Second I want to get keyword type is it organic or paid? If I will use ga:medium then will it give me type of searched keyword?
BTY using following function to get results
private function getResults(&$analytics, $profileId,$data) {
$optParams = array(
'dimensions' => 'ga:visitCount,ga:browser,ga:fullReferrer,ga:keyword,ga:country,ga:campaign,ga:medium'
);
return $analytics->data_ga->get(
'ga:' . $profileId, $data['start_date'], $data['end_date'], 'ga:visits',$optParams);
}
Please guide me.
Best Regards,
ga:searchKeyword is only for keywords from your internal site search. ga:keyword and ga:medium will give the desired result.
According to the documentation, ga:keyword tracks:
When using manual campaign tracking, the value of the utm_term campaign tracking parameter. When using AdWords autotagging or if a visitor used organic search to reach your property, the keywords used by visitors to reach your property. Otherwise the value is (not set).
ga:medium can be used to tell organic search and paid clicks apart. It tracks:
The type of referrals to your property. When using manual campaign tracking, the value of the utm_medium campaign tracking parameter. When using AdWords autotagging, the value is ppc. If the user comes from a search engine detected by Google Analytics, the value is organic. If the referrer is not a search engine, the value is referral. If the visitor came directly to the property, and document.referrer is empty, the value is (none).

Google-Analytics API to track Site Search?

So there's this nifty _trackPageview() api method on a tracker object, but is there a corresponding method that can be used to manually track a search? In other words, _trackPageview() reports to GA that a user hit a page. I want something like _trackSearch("terms") that would report to GA that a user searched for something.
Though not exactly what I was looking for, it seems that one can generate virtual page views to track search results programatically.
Suppose that you've set up a Site Search parameter called "q", so that when a URI is tracked that contains q=these+are+some+terms, GA will mark it as a search hit. One can use the _trackPageview() method to generate virtual search hits like so:
pageTracker._trackPageview('/custom/search?q=These+are+some+terms')
I pass search parameters by GET, so the URL for a search on "TEST" is
http://www.example.com/search?q=TEST
Selecting Content -> Site Search from my analytics account gives me a list of all keywords searched.
To learn more, check the documentation, especially the How do I set up Site Search for my profile? page.

Resources