Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Adobe Summit is happening now. Discover what's next in customer experience.
SOLVED

Create a data element containing scroll height of a popup

Avatar

Level 5

Hi all!

 

I want to create a data element that saves the distance a customer scrolls within a popup. I can return the value I'm after in the browser console using the following:

 

// Full height of div including scroll
var totalHeight = $("#myDialogContent")[0].scrollHeight;

// Initial height of div that needs to be subtracted
var initialHeight = $("#myDialogContent")[0].clientHeight;

// Actual element height value
var height = totalHeight - initialHeight;

// Scroll depth
var scroll = $("#myDialogContent").scrollTop();

var scrollPercentage = (scroll/height) * 100;

var rounded = Math.round(scrollPercentage);

return rounded;

 

This is the code I've used in the data element. However, when I try to return the value of the data element in the browser I get undefined each time.

 

Any help would be greatly appreciated. 

1 Accepted Solution

Avatar

Correct answer by
Level 5

This worked when I added it into a rule. I don't know why it didn't return through the console but I created a dummy data element change rule referencing the data element created using the above code and it worked as required.

View solution in original post

3 Replies

Avatar

Level 4

Might need some more context here. What kind of popup is it? Is it a whole new window popup? If so, you will need to make sure Launch is implemented on it as well.

Avatar

Level 5
It's not a new window (or content in an iframe from a third-party source). It's a modal that simply alternates between display:none and display:block on click of an open or close button. We have Launch coverage on the popup.

Avatar

Correct answer by
Level 5

This worked when I added it into a rule. I don't know why it didn't return through the console but I created a dummy data element change rule referencing the data element created using the above code and it worked as required.