AdWords is now Google Ads. Our new name reflects the full range of advertising options we offer across Search, Display, YouTube, and more. Learn more

Analytics
1.9K members online now
1.9K members online now
Ask questions about filter set-up and issues with using filters in Google Analytics reports
 
Guide Me
star_border
Reply

GA Regex to remove % numbers from URL

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hello,

 

I am trying to filter out The % and numbers from file names at the end of a URL that I am placing in the event label field when someone downloads a document. It looks like this: 

https://demo.democompany.com/brands/widgets/premium/Brand%20Documents/Americas%20All/Selling%20Resou...

 

I was able to pull out everything after the last slash but now I want to have another filter that searches and replaces the %20 with spaces. With a regex of %20 I only get the first instance replaced. Is there a way to make it global so that all of the %20's are replaced? I tried /%20/g to no avail.

 

Thanks,

 

Ivan

1 ACCEPTED SOLUTION

Accepted Solutions
Marked as Best Answer.
Solution
Accepted by topic author Ivan P
April 2017

Re: GA Regex to remove % numbers from URL

[ Edited ]
Explorer ✭ ✭ ✭
# 4
Explorer ✭ ✭ ✭

Hi @Ivan P,

Ok. Are you using link click tracking in GTM?

If you are, then you can create custom JS variable in GTM {{Decoded URI}}

function(){return decodeURI({{Click URL}})

and then use the same in event label. 

 

Let me know if that helps.

Thanks,
Ritwik B

View solution in original post

GA Regex to remove % numbers from URL

Explorer ✭ ✭ ✭
# 2
Explorer ✭ ✭ ✭

Hi @Ivan P,

Did you try using decodeURI(URL) or decodeURIComponent(URL) before sending URL to analytics?
Eg: ga('send','event', 'Category','action', decodeURI(url))

 

Thanks,
Ritwik B

GA Regex to remove % numbers from URL

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭

Thanks Ritwik - We are using Google Tag Manager so I don't think that is an option.

 

Regards,

 

Ivan

Marked as Best Answer.
Solution
Accepted by topic author Ivan P
April 2017

Re: GA Regex to remove % numbers from URL

[ Edited ]
Explorer ✭ ✭ ✭
# 4
Explorer ✭ ✭ ✭

Hi @Ivan P,

Ok. Are you using link click tracking in GTM?

If you are, then you can create custom JS variable in GTM {{Decoded URI}}

function(){return decodeURI({{Click URL}})

and then use the same in event label. 

 

Let me know if that helps.

Thanks,
Ritwik B

GA Regex to remove % numbers from URL

Visitor ✭ ✭ ✭
# 5
Visitor ✭ ✭ ✭

Ritwik - Thanks! That did the trick. I just had to add another } at the end of the command.