ktomasso
ktomasso

Reputation: 101

Using regex in Google Analytics to define a funnel

I'm attempting to set up a funnel in GA based on the destination page being /m/thanks(.*) where there are multiple one-time-offer pages in between that add a additional parameters to the URI.

The desired goal is to measure a Free signup. The flow looks like this..

The oto=no&oto=no signify that the user has declined both OTO pages, and therefore results in a free lead

The string after ?id= is dynamically generated, but does not contain &oto=no

Same id, but contains exactly one instance of &oto=no


I'm not sure the best way to represent step 3 and 4 to make sure I am recording only those pages.

Upvotes: 2

Views: 772

Answers (1)

Ro Yo Mi
Ro Yo Mi

Reputation: 15010

Description

This regex will:

  • validate the string does not have a &oto=no value
  • captures the query string value for ID
  • validates the string has /m/thanks?
  • allow the querystring attributes to appear in any order

^(?!.*?&oto=no)(?=.*?[?&]id=([^&]*))\/m\/thanks(?=[?])

enter image description here

  • ^ match the start of the string
  • (?!.*?&oto=no) look ahead an validate we can't find a oto=no key value set
  • (?=.*?[?&]id=([^&]*)) look ahead and validate we have the id and capture the value
  • \/m\/thanks(?=[?]) ensure the string starts with /m/thanks?

OR

This regex will:

  • validate you have 2 instances of oto=no in the string
  • capture the ID value
  • validates the string has /m/thanks?
  • allow the querystring attributes to appear in any order

^(?=(?:.*?&oto=no){2})(?=.*?[?&]id=([^&]*))\/m\/thanks(?=[?])

enter image description here

  • ^ match the start of the string
  • (?=(?:.*?&oto=no){2}) validate that oto=no exists twice in the query string
  • (?=.*?[?&]id=([^&]*)) capture the id value
  • .*?(?=[?]) capture the string upto the first ?

Upvotes: 1

Related Questions