Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-01-2012, 03:58 PM   PM User | #1
surfbird0713
New Coder

 
Join Date: Jun 2012
Location: South Carolina
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
surfbird0713 is an unknown quantity at this point
Need to dynamically pull in breadcrumb for Google Analytics Custom Variable

I am brand new to JavaScript and JSP coding, and have been tasked with something that feels over my head - hoping someone here can help me out.

The goal of my project is to dynamically populate fields to pull in the breadcrumb trail from a page into a custom variable in Google Analytics. What I need to do is populate the fields:
_gaq.push(['_setCustomVar',
2,
'BreadCrumb2',
'BreadCrumb3 | Breadcrumb 4 | Breadcrumb 5',
3
]);
with information from our breadcrumb trail that is set up like this (sometimes it only goes as deep as breadcrumb 3 but there could be up to 2 additional):

Home >> BreadCrumb2 >> BreadCrumb3 >> BreadCrumb4


I have played around with the existing code that sets up our breadcrumbs to no avail - Google Debugger throws an error whenever I have any versions of this code in there:

Code:
<c:set var="breadCrumbs" value="${categoryVB.breadCrumbs}" />
    <c:set var="topCategory" value="${breadCrumbs}" />
    <c:set var="subCategory" value="${breadCrumbs}" />
    <c:forEach var="breadCrumb" items="${breadCrumbs}" varStatus="status" > 
    </c:forEach>
<c:choose>
    <c:when test="${lastCmdName eq 'CategoryDisplay'}">
            <script type="text/javascript">
            _gaq.push(['_setCustomVar',
                                     2,                   // This custom var is set to slot #2.
      '<c:choose><c:when test="${status.index != 2}">
                    <c:out value="${topCategory.value}" />
                </c:when><c:otherwise>
        </c:otherwise></c:choose>',           // I am trying to tell it to pull in the information from the 2nd breadcrumb in the path  
      '<c:if test="${status.index != 2}" >
            <c:choose>
                <c:when test="${status.last}">
                    <c:out value="${subCategory.value}" />
                </c:when>
                <c:otherwise>
                    <c:out value="${topCategory.value}" />
                </c:otherwise>
            </c:choose>
        </c:if>',  // Trying to tell it to pull in the values after the 2nd breadcrumb if they are there, otherwise, fill this spot with the value of the 2nd breadcrumb. 
      3                    // Sets the scope to page-level.
   ]);
            </script>
        </c:when>
        <c:otherwise>
        </c:otherwise>
</c:choose>
I need to figure out how to manipulate that code, or is there a way I can use JavaScript to create a variable for me based on the information? So I can say:
JavaScript:

Tell me what it says between the first instance of >> and second instance of >> and create something called "Category"
and then I can put that into the Google code?
_gaq.push(['_setCustomVar',
2,
'JavaScriptVariableCategory',
'Everything After BreadCrumb3',
3 // Sets the scope to page-level.
]);
I would appreciate any and all advice, hints, help anyone can offer. I feel very lost here.

Thanks
surfbird0713 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:12 AM.


Advertisement
Log in to turn off these ads.