I think I might just be over complicating things instead of keeping it simple.
My question is: I want to capture the title of a blog post into a prop variable, and the author who wrote it into another prop variable.
My thought would be to create a page load rule focusing only on the path of /blog. From there I would scrape the page looking for the class that defines it, and then pass it into my prop through DTM.
<div class="field field-name-title">
<h2>Online Education</h2>
<div class="field field-name-body">
<p>
<em> by Author Name</em>
</p>
</div>
</div>
I create a page rule pick my prop and set it as: div.field.field-name-title.innerText
But when I set it, all I'm seeing being passed is the "div.field.field-name-title.innerText"
Am I tackling this in the wrong way?
The values you enter in a text field are literal, with the exception of %data_element%
syntax, which signifies a reference to a Data Element (there are a couple of other built-in variable references, as well).
Point is, if you want to populate your Adobe Analytics variable from scraping page content, you need to create a Data Element that returns the desired value, and then reference the Data Element in the text field for the Adobe Analytics variable.
That aside, your selector is wrong. What you've done is some weird mix of css selector and javascript syntax.
Below is an example of what you can do, based on your posted HTML:
<div class="field field-name-title">
<h2>Online Education</h2>
<div class="field field-name-body">
<p>
<em> by Author Name</em>
</p>
</div>
</div>
Data Element: Article Title
First, create a Data Element to get the article title from the page, based on your html structure.
Go to Rules >
Data Elements >
Create New Data Element
Fill out the fields with the following:
article_title
CSS Selector
div.field-name-title h2
text
[X]
Scrub whitespace and linebreaks using cleanTextThen, click Save Changes
Data Element: Article Author
Next, create another Data Element to get the article author from the page, based on your html structure.
Go to Rules >
Data Elements >
Create New Data Element
Fill out the fields with the following:
article_author
CSS Selector
div.field-name-body em
text
[X]
Scrub whitespace and linebreaks using cleanTextThen, click Save Changes
Page Load Rule: Populate Variables
Finally, within the various form fields of your Page Load Rule, you can now reference your Data Elements with %data_element_name%
syntax.
Tip: Once you start typing the Data Element name out (starting with %
prefix), DTM will show an auto-complete dialog, listing Data Elements matched.
If you need to reference the Data Element within a javascript custom code box within the Page Load Rule, you can use the following syntax:
_satellite.getVar('data_element_name');
Where 'data_element_name'
is the name of your Data Element.
Example:
s.prop1 = _satellite.getVar('article_title');
Note: Unlike the form field syntax, you should not wrap your Data Element's name with %