I have an html page with 3 sections that have same html markup in each - the only difference is a keyword of text in each section on the page I need to track.
I'm trying to make a function that will track each of the 3 sections on the page with an existing clicktrack function I have, as opposed to writing out the same tracking rules for all 3 sections multiple times.
The 3 keywords in each of the 3 sections I need to use in the function to track each section are
section 1: book
section 2: magazine
section 3: movie
I made an array of these values I want to use in each of the 3 sections respectively. Basically, for each of these keywords, I want to apply them for each of the 3 sections of the page in the tracking function like so:
- var media = ["book", "magazine", "movie"];
-
- $.each(media, function(i) {
- $('.section').each(function(){
- $(this).find('a').trackAs('Body/' + media[i] + '/Link');
- }
- });
Expected result:
Section 1 tracked as: Body/book/link
Section 2 tracked as: Body/magazine/link
Section 3 tracked as: Body/movie/link
I hope this is a clear example of what I'm trying to accomplish.
Thank you for your generous help in advance!!!