Ungazibhala Kanjani Futhi Uzivivinye Izihlungi zeRegex zeGoogle Analytics (Ngezibonelo)

Izinkulumo ezijwayelekile ze-Regex Google Analytics Filters

Njengezindatshana zami eziningi lapha, ngenzela iklayenti ucwaningo bese ngibhala ngalo lapha. Ukukhuluma iqiniso, kunezizathu ezimbalwa zokuthi kungani… okokuqala ukuthi nginezinkumbulo ezimbi futhi ngivame ukucwaninga iwebhusayithi yami ukuthola imininingwane. Okwesibili ukusiza abanye okungenzeka ukuthi nabo bafuna imininingwane.

Kuyini Ukuvezwa Okujwayelekile (Regex)?

I-Regex iyindlela yokuthuthuka yokusesha nokukhomba iphethini yezinhlamvu ngaphakathi kombhalo ukuze zifane noma zishintshe umbhalo. Zonke izilimi zesimanje zokuhlela zisekela ukuvezwa okujwayelekile.

Ngiyazithanda izinkulumo ezijwayelekile (regex) kepha kungakhungathekisa kancane noma kuthukuthelise ukufunda nokuhlola. I-Google analytics inamakhono athile amangalisayo… lapho ungakha khona ukubukwa ngezinkulumo ezijwayelekile noma ukuhlunga idatha yakho ngaphakathi kwezinkulumo ezijwayelekile.

Isibonelo, uma bengifuna ukubona nje ithrafikhi emakhasini ami wethegi, ngingahlunga i / tag / esakhiweni sami se-permalink ngokusebenzisa:

/tag\/

I-syntax ibucayi lapho. Uma ngivele ngisebenzise i- "tag", bengizothola wonke amakhasi anethegi yethemu kuwo. Uma ngisebenzise "/ umaki" khona-ke noma iyiphi i-URL eqala ngomaki izofakwa, njenge / ukuphathwa kwamathegi ngoba i-Google Analytics izenzakalelayo ukufaka noma yimuphi umlingiswa ngemuva kwenkulumo ejwayelekile. Ngakho-ke, ngidinga ukuqinisekisa ukuthi ngine-slash elandelayo efakiwe… kepha kufanele ibe nomlingiswa wokuphunyuka kuyo.

isihlungi sekhasi regex

Izisekelo zeRegex Syntax

syntax Incazelo
^ Iqala nge
$ Kugcina ngo-
. Ikhadi lasendle lanoma yimuphi umlingiswa
* Uziro noma ngaphezulu kwento edlule
.* Ifanisa noma yiziphi izinhlamvu ku-
? Uziro noma isikhathi esisodwa sento edlule
+ Isikhathi esisodwa noma eziningi zento edlule
| Isisebenzisi se-OR
[abc] A noma b noma c (kungaba yinombolo yezinhlamvu)
[az] Ububanzi buka-a kuye ku-z (kungaba yinoma iyiphi inombolo yezinhlamvu)
[AZ] Ububanzi buka-A kuye ku-Z (osonhlamvukazi)
[0-9] Ububanzi buka-0 kuye ku-9 (kungaba yinoma iyiphi inombolo)
[a-zA-Z] Ububanzi bokuthi a kuye ku-Z noma u-A kuye ku-Z
[a-zA-Z0-9] Zonke izinhlamvu zamagama
{1} Isibonelo esingu-1 (kungaba yinoma iyiphi inombolo)
{1-4} Ububanzi bezimo ezi-1 kuye kwezingu-4 (kungaba yinoma iyiphi inombolo)
{1,} 1 noma izimo eziningi (kungaba yinombolo)
() Qoqa imithetho yakho
\ Balekela izinhlamvu ezikhethekile
\d Uhlamvu lwedijithi
\D Uhlamvu okungewona amadijithi
\s Isikhala esimhlophe
\S Isikhala esingemhlophe
\w iZwi
\W Okungelona igama (izimpawu zokubhala)

Izibonelo zeRegex ZeGoogle Analytics

Ngakho-ke ake sibeke ezinye izibonelo lapho zabathile Izihlungi ngokwezifiso. Omunye wozakwethu wangicela usizo lokukhomba ikhasi langaphakathi elinendlela ye / inkomba ngaphezu kwakho konke okuthunyelwe kwebhulogi okwabhalwa nonyaka ku-permalink:

Iphethini yami yesihlungi yangokwezifiso yenkambu yokuhlunga Cela i-Url:

^/(index|[0-9]{4}\/)

Lokho kusho ngokuyisisekelo ukubheka / inkomba NOMA noma iyiphi indlela enezinombolo ezi-4 ephela nge-slash trailing. Ngidale ukubuka ku-Analytics ngangeza lokhu njengesihlungi:

Isihlungi sokubuka se-Google Analytics

Nazi ezinye izibonelo ezimbalwa:

  • Unebhulogi enonyaka endleleni ye-URL permalink futhi ufuna ukuhlunga uhlu kunoma yimuphi unyaka. Ngakho-ke ngifuna noma yimaphi amadijithi ezinombolo ezi-4 alandelwe i-slash elandelanayo. Cela iphethini yesihlungi se-URl:

^/[0-9]{4}\/

  • Ufuna ukuqhathanisa wonke amakhasi akho lapho isihloko sinakho isitifiketi or ukunika isitifiketi kuwo. Iphethini lesihlungi sesihloko sekhasi:

(.*)certificat(.*)

  • Ufuna ukuqhathanisa amakhasi amabili okufika ngokuya nge-Campaign Medium yawo edluliswe kufayela le- I-URL yomkhankaso we-Google Analytics njenge-utm_medium = mail ngqo or ukusesha okukhokhelwe.

(direct\smail|paid\ssearch)

  • Ufuna ukuqhathanisa yonke imikhiqizo engamahembe amadoda ngokususelwa endleleni ye-URL. Cela iphethini yesihlungi se-URl:

^/mens/shirt/(.*)

  • Ufuna ukuqhathanisa wonke amakhasi abhalwe inombolo ye-URL ephela ngenombolo. Cela iphethini yesihlungi se-URl:

^/page/[1-9]*/$

  • Ufuna ukukhipha uhla lwamakheli we-IP. Ungafaki iphethini yesihlungi sekheli le-IP:

123\.456\.789\.[0-9]

  • Ufuna ukufaka ikhasi le-thankyou.html lapho okuthunyelwe kube yimpumelelo ngokuya ngombuzo we-queringstring success = true. Cela iphethini yesihlungi se-URl:

thankyou\.html\?success=true

Ungazivivinya Kanjani Izinkulumo zakho zeRegex

Esikhundleni sezilingo nephutha ngaphakathi kwe-Google Analytics, ngivame ukuvele ngiye ku regex101, ithuluzi elihle lokuhlola izinkulumo zakho ezivamile. Ize ikwephulele i-syntax yakho futhi inikeze imininingwane yesisho sakho esijwayelekile:

izinkulumo ezijwayelekile regex101

Yakha, Vivinya, futhi ulungise iphutha i-Regex

UCABANGANI?

Le sayithi isebenzisa i-Akismet ukunciphisa ugaxekile. Funda ukuthi idatha yakho yokuphawula isetshenziswa kanjani.