1

I have a website that's a collection of articles. The longer articles have a 'middle' < div > about halfway through the text, where I can insert ads or whatnot. Shorter articles and miscellaneous pages don't have this < div >.

I'm trying to figure out how to track how many pageviews I get only on the articles with the 'middle' < div >. Does anyone know how to do it?

*Note that I just want to see how often the articles with that < div > are loaded. I don't care about whether the user specifically scrolls down far enough to literally see the < div > or whether they interact with it in any way.

4
  • Does your div content has a different category in the URL from your regular content? (Or anything that specifies that these articles are different, other than the presence of the div?) If yes, you can use Segments or Views. Otherwise, you can use Events, but those are for clicks, not for pageviews. – Henry Visotski Jun 30 '17 at 16:24
  • 1
    I don't think events is correct. That is for user interaction. You could possibly use a "dimension" to record this information. – Stephen Ostermiller Jun 30 '17 at 16:28
  • Henry Visotski: No, there's nothing in the urls to distinguish articles with and without the div – Chris M Jun 30 '17 at 16:34
  • Stephen - agree - so if all of his divs of this type have an id set, he should be able to specify that id as a dimension, right? – Henry Visotski Jun 30 '17 at 16:54
1

A custom dimension is the right answer here. You can create the custom dimension and scope it to hit. Then, before the pageview send in Google Analytics, you'll want to detect if that <div> is present (either by the template or specifically with a JS selector to check its .length) to set the value of the custom dimension (which can either be a specific string for every one, or a dynamic string based on the div content/attributes).

Then in Google Analytics, you can create a segment based on traffic to pages with that particular div. Or just use secondary dimensions in existing reports to access the data.

Now (and I know you didn't ask for this), if you did want to get additional information I'd recommend checking out the impressionTracker in Autotrack.js where you would send events (and custom metrics) to determine how often that particular <div> was actually seen by users. I just wanted to include that info for future consideration (and for anyone else that finds this question and is curious).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.