Remove Varying Domain Names from URLs Using a Calculated Field / REGEX - regex

I am attempting to create a calculated field called "Page" using a custom CSV upload data source - a list of URLs from several websites combined into one big list of thousands of URLs on dozens of different domain names in Datastudio.
In the CSV, I have a field called "URL". It contains each pages full URL including the Root Domain Name.
I have another field for each of those records called "Root Domain Name". It has the Root Domain Name for each URL.
I'd like to extract the Root Domain Name identified in one field from the URL identified in another field, leaving just the "Page" path. The URLs vary in terms of Top Level Domain - some are .com, some are .co.uk, some are .fr, etc.
Ultimately, the output would be something like this:
www.domain.com/test-page - > /test-page
www.domain.co.uk/test-page - > /test-page
www.domain.fr/test-page -> /test-page
etc.
It seems like it'd be something like this but obviously isn't working hence my presence here today:
REGEXP_REPLACE(URL,Root Domain Name,'')
I am thinking that removing the value of one field from the value of another is one way of getting at it but there might be a better way of simply manipulating the URL field to remove everything prior to the 3rd / too.
I need to keep the first / after the Domain Name (a data formatting issue).
I'll be plugging away at this one and figured there has to be someone out there that has seen this before so welcome any input.
Have a good day everyone.

I use the following to decompose full URL in Data Studio:
URL Path: REGEXP_EXTRACT(Url, '^https?://[^/]+(/[^?#]*)')
URL Query: REGEXP_EXTRACT(Url, '[^?]+\\?(.+)')

Related

Django (GET) - Is it posible to pass multiple values in only one parameter, instead of multiple parameters called the same

I'm developing an web app with Django to query and download data from multiple weather stations. It's almost everything good but something that I don't like it's that when I filter by stations, the form passes them to the URL like this:
https://my-server/stations?station_name=1&station_name=2&station_name=3
And since the number of selected stations can reach more than 250 (this added to the fact that spatial data are also passed in the URL as coordinates, polygons...), I would like to know if there is any way to obtain the "station_name" parameter in a list format like this or similar, for me to later divide it in my views.py:
https://my-server/stations?station_name=1%3B2%3B3
On the other hand, I'm not sure if there are any contraindications when generating too long URLs, if not I have no problem maintaining the current format, but otherwise I would like to find a solution.
Thanks in advance
Edit: If it helps, I'm using the Select2MultipleWidget widget for this field.

Power BI filtering URL query Parameters

I am trying to filter the Power BI reports using the URL query filters.The field name I am trying to filter has space so I am passing in the parameter like
?filter=DW_Project/Project_x0020_Manager_x0020_Name eq 'Max Hex'
But the reports are being filtered
I am getting the error like
Can anyone please tell what I am missing here.
The encoding looks correct. Indeed the space is escaped with _x0020_ as per the documentation. Check the name of the table and the field and make sure they are the same. Note that these names are case sensitive. You will get this error if they do not match. Since you posted only images, I can't check, but DW__Project looks like containing not one, but two underscores, while it is only one in your URL.

Google geo-coding returns different results if URL is encoded versus if it is not

Results of url https://maps.googleapis.com/maps/api/geocode/json?address=75019&sensor=false&components=postal_code:75019|country:US is different from results of url https://maps.googleapis.com/maps/api/geocode/json?address=75019&sensor=false&components%3Dpostal_code:75019|country:US
The only difference between the two url's is that the "=" character after "components" is url encoded in the second url. As a result in second url: I get 2 results back, one for Paris & one for Texas, which is undesirable. I want results just for country = US. We are using the second url in production, but would like the results that we get from the first url.
Issue is that even though the filter clearly mentions the country as US, why am I getting an address from France?
Any solution or insights? Is the diagnosis correct?
You're not specifying the country as US in the second URL:
The second url gives google a parameter named "components%3Dpostal_code:75019|country:US" with no content, while the first one gives google a parameter named "components" with a content of "postal_code:75019|country:US" - the = sign is important as the separator between parameter name and value. If you url-encode it, it is not considered for this purpose anymore.
So, you should not URL-encode the equals sign if it should signify the separation between a parameter name and its value... meaning you will have to change your production code to produce the first URL. The second one just isn't representing what you want to express.
Since you don't use any other url-encoded characters (at least not in the link shown above), it might also work to do a separate Url-decoding step somewhere before sending the request to google (if you absolutely can't change production code).

Regex for Google analytics advanced segment based on custom variable value

Trying to create an advanced segment (include) using regex (or any other filter mechnanism, contains with just the substring isn't working either) which uses the value of the custom variable value.
It ought to be straightforward, but it's driving me insane. I currently have this regex:
.*CLAS_LIBRARIES.*
which rightly matches a custom variable value of:
HOME/CLASMAIN/CLAS_LIBRARIES/
but when I apply the segment and then browse the custom variable values in the report, it contains values like:
HOME/
/museumcollections/
HOME/MAPS/
Tried wrapping it like this:
.*(CLAS_LIBRARIES).*
(.*)(CLAS_LIBRARIES)(.*)
to no avail.
What the hell is going on, and am I an idiot?
What's the scope of your custom variable? Can multiple sessions have different values?
Advanced segments will return any data that matches your query (e.g. in case of creating a segment for a specific page, GA will return data for all user activity which included that specific page as part of their navigation).

webservice for autosuggest on city names / postal codes including long-lat coordinates?

i'm looking for a webservice, to be used for an autocomplete field,
where people can fill in either a postal code / city name or both
this service will need all cities in Europe, so we can use it for all country websites.
and in a later stadium we want to keep the world open for asia and america so this would be a plus.
preferably it would also return the long-lat coordinates for the locations,
Now it is a free textfield, after leaving the field, we hit the google geocoding service,
to find coordinates... preferably i would tie these two together.
so we don't have to query 2 services for one thing.
does anyone know of the existance of such a service online somewhere?
or would you suggest to build our own database with cities / postal codes / coordinates?
if so we would need to get the content from somewhere too, and i was trying to avoid that issue :)
I recently searched for a similar service, in vain.
I wanted my users to have auto-complete on entering a city name, and once a city is chosen I needed to pass the name and lat/long onto the Google API. In the end I did this: -
downloaded the geonames allcountries.zip, full extract: this
Imported it into a SQL DB via SSIS (about 7.5 million records!)
Wrote a simple query to extract just the cities (only the PPLC, PPLA and PPLA2 records).
This left me with a manageable table of 9112 records (with lat / long and country code) which covers all the cities in the world. I then wrote my own code to query the data.
Not ideal, but I needed a solution.
I know this post is very old but for thouse who are looking for a simple solution that can be integrated in 5 minutes here is the link:
Geocomplete jQuery...
For my case I followed this steps:
1 - Download the plugin from here.
2 - Add the jquery.geocomplete.js or jquery.geocomplete.min.js file into your javascript folder of your project.
3 - Call this file in script tags on the html page where you have the input field that you have to autocomplete with cities:
<script src='/PathToTheFile/jquery.geocomplete.js'></script>
4 - To convert an input into an autocomplete field, simply call the Geocomplete plugin in script tags: <script>
$("#IdOfTheInputField").geocomplete(); // Option 1: Call on element.
$.fn.geocomplete("input"); // Option 2: Pass element as argument.
</script>
5- You can check for the complete list of options on the link provided at the top.
Hope that this helped!