Expand my Community achievements bar.

SOLVED

DTM - How to match the home page in a page load rule

Avatar

Level 2

Rookie question:  How do I write a Path based condition that will detect my homepage only? 

I'd like it to match :

THIS: http://www.landsend.com/

NOT: http://www.landsend.com/shop/swim

NOT: http://www.landsend.com/products/womens-ruffle-thongs/id_265218

NOT: https://www.landsend.com/co/ShoppingBag.html

or any other thing that is not the base URL.  

I tried using "/" on the PATH condition but it didn't work for me. 

I ended up creating a data element called "dtm_pathName" which is the Javascrip Object "window.location.pathname".  I can then test this against "/" to see if it is root directory.  HOWEVER, this rule needs to be evaluated on the client which seems a little inefficient and clutters up the debug logs in the console with messages like: 

"SATELLITE: Condition function (){return _satellite.textMatch(_satellite.getVar("dtm_pathName"),"/")} for rule "TNT - mBoxGlobal HomePage" not met."

There has to be a trick.  Any advice? 

1 Accepted Solution

Avatar

Correct answer by
Employee

Hi Stewart,

Yes, I have no issues when testing this solution. Here are some screenshots of what this looks like in the UI.

The rule condition should look like this: 

[img]homepage-01.png[/img]

The test script:

[img]homepage-02.png[/img]

Debug on the home page where the rule fires:

[img]homepage-03.png[/img]

Debug on a different page where the rule does not fire:

[img]homepage-04.png[/img]

If this doesn't help then can you post a link to your test site, or send it to me directly so that I can take a look at the page?

Thanks,

Joel

View solution in original post

9 Replies

Avatar

Former Community Member

You could turn on regular expressions for that field to achieve what you want.

When you click into the field (i.e. for path - include), you should see a little box with "Regex" in it hover there - just click it over to ON.

Then, set your regular expression to be:

^http:\/\/www.landsend.com\/$

The caret (^) indicates that it has to start with this exact path, and the dollar sign indicates it has to end with this exact path. (The forward slashes have to be escaped since those are used to denote the beginning and end of the regular expression.)

HTH!

- Carey

Avatar

Level 2

Thanks for the response, but it doesn't seem to work.  Have you tried it on your end?  

I put in exactly what you suggested and the rule still fires on every page that begins with "http://www.landsend.com/"

I've tried a great number of regular expressions to no avail.  

I might add that within DTM the little regex tester indicates that your solution should work, but in application it does not.   Thus my question. 

Avatar

Employee

Hi Stewart,

Using regex is probably the way to go, but this use case is a bit more complex than it may first appear. For instance, the match probably needs to take into account situations like variations in protocol (http vs https), the actual homepage file name (index.jsp), query params (?var1=1&var2=1), etc. in addition to simply excluding alternate filenames like /page.html at the end of the path.

A simple match would be ^(https?:\/\/)?www.landsend.com\/?$

Use the regex "test" in the DTM UI to evaluate examples. In addition to using the path "include" option you may also want to consider explicitly excluding pages using the "exclude" option if that is easier. However, all of the matching can be done in a single path "include" so try that first.

Let us know if that resolves the situation for you or if you need some additional help.

-Joel

Avatar

Level 2

Joel Stachowicz wrote...

Hi Stewart,

Using regex is probably the way to go, but this use case is a bit more complex than it may first appear. For instance, the match probably needs to take into account situations like variations in protocol (http vs https), the actual homepage file name (index.jsp), query params (?var1=1&var2=1), etc. in addition to simply excluding alternate filenames like /page.html at the end of the path.

A simple match would be ^(https?:\/\/)?www.landsend.com\/?$

Use the regex "test" in the DTM UI to evaluate examples. In addition to using the path "include" option you may also want to consider explicitly excluding pages using the "exclude" option if that is easier. However, all of the matching can be done in a single path "include" so try that first.

Let us know if that resolves the situation for you or if you need some additional help.

-Joel

 


I agree that regex SHOULD be the way to go if a simple path match can't do it.  The problem that I have is that the "test" regex window tells me one thing, but in application, it does not work.

This expression handles all the conditions that I need to handle and it "tests" well in the interface.  ^http://www\.landsend\.com[/]?[?]?[^/?]*$

The same is true of the simple expression suggested above.  In application, though, it does not work.  Again, I have to ask, have you gone beyond the "test" box in the interface and tried this on page load rule in action? If you have, and it works for you, then I am probably doing something else wrong. 

Avatar

Employee

Hi Stewart,

Sorry, I got ahead of myself in the explanation and meant location.href when I was talking about path instead of how DTM uses the term "path" in rules.

"Path" in DTM rule conditions means location.pathname + location.search and not the other components of location like location.protocol, etc. So with the example http://www.landsend.com the DTM "path" is "/" and not the full location.href which would be http://www.landsend.com/ that you are expecting. There is a built-in DTM data element that also references this same value ("URI").

Since you are really trying to match "/" then use an abbreviated version of the regex and it should work as you expect. In my previous example, ^\/?$ would be the equivalent.

Hope that helps,

Joel

Avatar

Level 2

Hi Joel,  

I'm still not getting it to work.  Have you tried this yourself and proven it to work? 

If I understand your suggestion, you are saying that I should be able to create a PATH condition as INCLUDE ^\/?$ with regexp turned on to detect the homepage of the website.  

Thanks,

-Stew

Avatar

Correct answer by
Employee

Hi Stewart,

Yes, I have no issues when testing this solution. Here are some screenshots of what this looks like in the UI.

The rule condition should look like this: 

[img]homepage-01.png[/img]

The test script:

[img]homepage-02.png[/img]

Debug on the home page where the rule fires:

[img]homepage-03.png[/img]

Debug on a different page where the rule does not fire:

[img]homepage-04.png[/img]

If this doesn't help then can you post a link to your test site, or send it to me directly so that I can take a look at the page?

Thanks,

Joel

Avatar

Level 2

In the words of Matthew Mcconaughey, "Alright, Alright, Alright!" 

Don't know what I was doing wrong the first time around, but it's working now.  

I had to modify the regexp a bit so that I could match the home page with or without query string arguments. 

The pattern I ended up with is:  ^[/]?[?]?[^/?]*$

Thank you much!  I'm so glad to have a good solution for this. 

 

-Stew