DTM: How to save 404 errors to pagename, eVar etc.

Avatar

Avatar

Antti_Ko

Avatar

Antti_Ko

Antti_Ko

15-10-2015

If user goes to url that doesn't exist and then the browser gets status code 404 error aka page not found. If that happens, I would then like to save "errorpage" to s.pageName and the status code "404" to eVar5. Any ideas which would be the easiest or the best way to do this with dynamic tag management? I didn't see any rules for status codes in the "page load rules" section. Do I have to again (!) make some kind of custom script? Thanks for all the help.

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

Erika_Barber

Employee

Avatar

Erika_Barber

Employee

Erika_Barber
Employee

15-10-2015

Have you used the DTM debug mode to verify that your rule is actually firing?  If the rule is not firing at all, something within the Conditions section is incorrect.  If the rule is firing and your tag is not, then you'll want to double-check your custom code.

You can enter _satellite.debug(true); into your developer console to turn on debug messages. 

Answers (8)

Answers (8)

Avatar

Avatar

Antti_Ko

Avatar

Antti_Ko

Antti_Ko

15-10-2015

Yes, I did like that, although that was just an example. But still don't get it to work.

Let's walkthrough this.

Our image: <img src="/folder1/folder2/images/404_head.png">

I can do this with event based rules, so no data element is needed?
event type: element exists
Apply event handler directly to element (didn't check)
Element Tag or Selector: img
Checked "Manually assign properties & attributes" and added, property: src and value: 404_head.png (no regex)
And I have to add some kind of rule?

Avatar

Avatar

Erika_Barber

Employee

Avatar

Erika_Barber

Employee

Erika_Barber
Employee

15-10-2015

That should work if the path for your 404 image contains "404.jpg".  Here is a reference on selectors so you can be sure you're using the correct syntax:  http://www.w3schools.com/cssref/css_selectors.asp

Avatar

Avatar

Antti_Ko

Avatar

Antti_Ko

Antti_Ko

15-10-2015

Thanks Rudi. Don't get it to work anyway. If I want fire my "404" rule based on "404 image" exist, then what should I put to
"Element Tag or Selector" = img (?)
" = src (?)
"Value"= 404.jpg (?)
Not working.

Avatar

Avatar

Rudi_Shumpert

Employee

Avatar

Rudi_Shumpert

Employee

Rudi_Shumpert
Employee

15-10-2015

"element exists"  is in the Event criteria drop down within an Event Based Rule.

 

[img]Screen Shot 2013-11-15 at 11.17.20 AM.png[/img]

Avatar

Avatar

Antti_Ko

Avatar

Antti_Ko

Antti_Ko

15-10-2015

Thanks. Where can I find that "element exists"?

Avatar

Avatar

Erika_Barber

Employee

Avatar

Erika_Barber

Employee

Erika_Barber
Employee

15-10-2015

Yes, you could write some custom script in the Conditions > Criteria > Custom Code section and return true only if you detect the 404 http status code.  

If you can standardize the page in someway to have a consistent identifier, like a query string parameter or javascript object that reflects the http status code, you could use that in a Data Element and look for that in your Conditions.  If the 404 image on the page was consistent, you could use "element exists" criteria and use a CSS selector to look for that image.

Obviously there are many different ways to do this, since the http status code is not a built-in criteria in the rules.

Avatar

Avatar

Antti_Ko

Avatar

Antti_Ko

Antti_Ko

15-10-2015

The problem is that url does not contain any unique information about 404 error. We can have http status code 404 on any url that does no exist. Of course we have unique 404 error image and with that I can create rule, but what if somebody change the image name/url. It would be much more reliable if I could make this kind of rule "if http status code is 404 then fire my rule X", but this is not possible? Maybe it's again possible to do some kind of custom script that fires my rule if http status code is 404. Have use Google to find help to make this kind of custom javascript, if you can't tell directly? 😃

Avatar

Avatar

Erika_Barber

Employee

Avatar

Erika_Barber

Employee

Erika_Barber
Employee

15-10-2015

To track pages like this, you would want to make sure you have DTM code embedded on your 404 error page.  Then create a DTM page load rule based on a unique identifier for this page type.  For example, if the URL contains "404error", then use the Path criteria in your Condition and set "404error" in the value field.  

Then in the Adobe Analytics section of the rule, you can set your eVar5 in the UI.  You should not set the pageName as errorType, because error pages are tracked in a separate variable called pageType.  You can use the Custom Page Code editor and enter this to track the error pages:

s.pageType = "errorPage";