Esempio n. 1
0
 /// <summary>Overload to set custom suites based on section details.</summary>
 /// <param name="detail">Nav details for the current page</param>
 public void SetReportSuites(SectionDetail detail)
 {
     try
     {
         string customSuites = detail.GetWASuites();
         if (!string.IsNullOrEmpty(customSuites))
         {
             SetReportSuites(customSuites);
         }
     }
     catch (Exception ex)
     {
         log.Debug("WebAnalyticsPageLoad:SetReportSuites(): Exception encountered while retrieving web analytics suites.", ex);
     }
 }
Esempio n. 2
0
        public string Tag()
        {
            StringBuilder output       = new StringBuilder();
            string        reportSuites = "";

            // Fire off old constructor actions
            DoLegacyPageLoad();

            if (WebAnalyticsOptions.IsEnabled)
            {
                output.AppendLine("");
                output.AppendLine(WEB_ANALYTICS_COMMENT_START);

                // Report Suites JavaScript variable (s_account) must be set before the s_code file is loaded
                // Get custom suites that are set on the navon. Default suites are being set in wa_wcms_pre.js
                try
                {
                    string        sectionPath  = pgInstruction.SectionPath;
                    SectionDetail detail       = SectionDetailFactory.GetSectionDetail(sectionPath);
                    string        customSuites = detail.GetWASuites();
                    if (!string.IsNullOrEmpty(customSuites))
                    {
                        reportSuites += customSuites;
                    }
                }
                catch (Exception ex)
                {
                    log.Debug("Tag(): Exception encountered while retrieving web analytics suites.", ex);
                    reportSuites += "";
                }

                // Output analytics Javascript to HTML source in this order:
                // 1. wa_wcms_pre.js source URL
                // 2. Snippet to set s_account value
                // 3. NCIAnalyticsFunctions.js source URL (see line 47)
                // 4. s_code source URL
                // 5. Channel, Prop, eVar, and Event info
                // Note: as of 08/2018, the web analytics javascript is hosted on DTM
                output.AppendLine("<script language=\"JavaScript\" type=\"text/javascript\" src=\"" + WaPre + "\"></script>");
                output.AppendLine("<script language=\"JavaScript\" type=\"text/javascript\">");
                output.AppendLine("<!--");
                output.AppendLine("var s_account = AnalyticsMapping.GetSuites(\"" + reportSuites + "\");");
                output.AppendLine("-->");
                output.AppendLine("</script>");

                output.Append(pageLoadPreTag.ToString());

                if (pageWideLinkTracking)
                {
                    // Page-wide link tracking is current not used - this may be implemented at a future date
                    // This however should just output a JS function call that lives in the NCIAnalytics.js
                    // file instead of the inline code.
                    //output.AppendLine(LinkTrackPageLoadCode().ToString());
                }

                if (channel != "") // if channel is set, output them to the tag
                {
                    output.AppendLine("s.channel=" + DELIMITER + channel + DELIMITER + ";");
                }

                if (pageName != null) // if pageName is not null (empty string ok), output them to the tag
                {
                    output.AppendLine("s.pageName=" + DELIMITER + pageName + DELIMITER + ";");
                }

                if (pageType != "") // if pageType is set, output them to the tag
                {
                    output.AppendLine("s.pageType=" + DELIMITER + pageType + DELIMITER + ";");
                }

                if (props.Count > 0) // if props are set, output them to the tag
                {
                    foreach (var k in props.Keys.OrderBy(k => k))
                    {
                        output.AppendLine("s.prop" + k.ToString() + "=" + props[k] + ";");
                    }
                }

                if (evars.Count > 0) // if eVars are set, output them to the tag
                {
                    var items = from k in evars.Keys
                                orderby k ascending
                                select k;
                    foreach (int k in items)
                    {
                        output.AppendLine("s.eVar" + k.ToString() + "=" + evars[k] + ";");
                    }
                }

                if (events.Count > 0)  // if events have been defined, output then to the tag
                {
                    output.AppendLine("s.events=" + DELIMITER + string.Join(",", events.ToArray <string>()) + DELIMITER + ";");
                }

                output.AppendLine("");

                // Add calls to special page-load functions for a specific channel
                bool firstTime         = true;
                bool containsFunctions = false;
                foreach (string function in WebAnalyticsOptions.GetSpecialPageLoadFunctionsForChannel(channel, language))
                {
                    if (function != "")
                    {
                        if (firstTime)
                        {
                            output.AppendLine("//Special Page-Load Functions (SPLF)");
                            firstTime = false;
                        }
                        string[] functions = function.Split(',');
                        foreach (string item in functions)
                        {
                            output.AppendLine("if(typeof(NCIAnalytics." + item.Trim() + ") == 'function')");
                            output.AppendLine("   NCIAnalytics." + item.Trim() + "();");
                        }
                        containsFunctions = true;
                    }
                }
                if (containsFunctions)
                {
                    output.AppendLine("");
                }

                output.AppendLine(pageLoadPostTag.ToString());
            }
            return(output.ToString());
        }