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
4.2K members online now
4.2K members online now
Learn how to set up goals and Ecommerce tracking, verify accuracy of attribution traffic sources, and discuss funnel visualization, Multi-Channel Funnels, the Goal Flow Report, and Enhanced Ecommerce
 
Guide Me
star_border
Reply

Goal and regular expressions

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hi,

I am setting up a goal with RegEx, Can anyone confirm if the below set up would be correct?

 

this is a sample of the original link, where the numbers vary each time:

 

/book.php?id=10785379&op=thanks

REgEx:

/book\.php\?id= [0123456789]&op=thanks

 

Would the square brackets be correct like this? Even if I have only 8 characters in the id, but I have 10 characters to choose from?

 

thanks,

Brigi

1 Expert replyverified_user
1 ACCEPTED SOLUTION

Accepted Solutions
Marked as Best Answer.
Solution
Accepted by topic author Brigitta S
June 2016

Re: Goal and regular expressions

Top Contributor
# 5
Top Contributor

Hi @Brigitta S and @ChrisSN,

 

Just to clarify, the Google regex engine does not require you to escape forward slashes (I still do it all the time because to me it's "proper" regex, cf. https://support.google.com/analytics/answer/1034324?hl=en).

 

To match this "/book.php?id=10785379&op=thanks", you could do something like this:

/book\.php\?id=[0-9]+&op=thanks

where you just need to have at least one digit.

 

Hope this helps.

 

 

 

 

Nicky Yuen, Google Analytics Top Contributor
Was my response helpful? If yes, please mark it as the ‘Best Answer.’ Learn how here.
Find me on: Google+ | LinkedIn

View solution in original post

Re: Goal and regular expressions

Follower ✭ ☆ ☆
# 2
Follower ✭ ☆ ☆

Re: Goal and regular expressions

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭
Hi Chris,

I don't see any square brackets, list of digits or range of digits in this option? Or I don't see what was her original sample url either.
Would you know which of the below regex would be correct for the posted sample url?

Sample url:

/book.php?id=10785379&op=thanks

REgEx options:

/book\.php\?id= [0123456789]&op=thanks

/book\.php\?id= [0-9]&op=thanks


thanks,
Brigi

Re: Goal and regular expressions

[ Edited ]
Follower ✭ ☆ ☆
# 4
Follower ✭ ☆ ☆

Hi,
I meant the answer below her post, which is about the "\" escape character.
Try this, quote from user Andrzej S:

In all setups that you provided you forgot to "escape" "/" character. In regular expression slash is a special character that you need to escape with "\" if you want to use it as regular slash (like in URL). To make it more clear here is an example:

For goal that has URL path like "/checkout/thank_you" regular expression would be would be "\/checkout\/thank_you".

Try to "\/" every "/" that you have in the first setup you pasted on the screens and it should work just fine. Also for your Homepage you can try "^\/{1}$" but "^\/$" should be just fine.

If you're not sure I would strongly recommend using regexr.com. It's a simple yet great tool to test your regular expressions.

I hope this makes it clearer, and

Sorry, dont know about the squared brackets.

Marked as Best Answer.
Solution
Accepted by topic author Brigitta S
June 2016

Re: Goal and regular expressions

Top Contributor
# 5
Top Contributor

Hi @Brigitta S and @ChrisSN,

 

Just to clarify, the Google regex engine does not require you to escape forward slashes (I still do it all the time because to me it's "proper" regex, cf. https://support.google.com/analytics/answer/1034324?hl=en).

 

To match this "/book.php?id=10785379&op=thanks", you could do something like this:

/book\.php\?id=[0-9]+&op=thanks

where you just need to have at least one digit.

 

Hope this helps.

 

 

 

 

Nicky Yuen, Google Analytics Top Contributor
Was my response helpful? If yes, please mark it as the ‘Best Answer.’ Learn how here.
Find me on: Google+ | LinkedIn

Re: Goal and regular expressions

Visitor ✭ ✭ ✭
# 6
Visitor ✭ ✭ ✭
Hi Nicky,

Thanks I'll test this and let you know if it worked. Just to check the + is to make sure that &op may vary, it would track it?

thanks,
Brigi

Re: Goal and regular expressions

Top Contributor
# 7
Top Contributor
Hi, Brigi,

The "+" indicates that there are at least 1 of the preceding character(s). It applies to the group that comes just before it, so "[0-9]+" translates to "at least one number between the range of 0 to 9".

"&op" is just an exact string match. Is that variable for you?

What are the other possibilities for your string?
Nicky Yuen, Google Analytics Top Contributor
Was my response helpful? If yes, please mark it as the ‘Best Answer.’ Learn how here.
Find me on: Google+ | LinkedIn

Re: Goal and regular expressions

Explorer ✭ ✭ ☆
# 8
Explorer ✭ ✭ ☆
If your id is always 8-digit long then I would see your regex as:

\/book\.php\?id=[0-9]{8}&op=thanks

I know that Google oficially does not require to escape slash character but I happened couple of times to have a proble with it so to be on a safe side I always do that - at least it couldn't hurt.