/// <summary>
        /// This method returns a list of all special page load function for a given channel.
        /// </summary>
        /// <param name="channelName">The name of the channel</param>
        /// <param name="language">The language of the related suite.</param>
        /// <returns>A string[] containing reporting suite.</returns>
        public static string[] GetSpecialPageLoadFunctionsForChannel(string channelName, string language)
        {
            List <string> rtnFunctions = new List <string>();

            WebAnalyticsOptions.Initialize();

            if (_webAnalyticsConfig != null)
            {
                var functions = from reportingSuite in _webAnalyticsConfig.ReportingSuites.Cast <ReportingSuiteElement>()
                                where
                                (((reportingSuite.Language == "") || (reportingSuite.Language == language)) &&
                                 (reportingSuite.EnabledForAllChannels ||
                                  //When looking for channel make it case insensitive.
                                  reportingSuite.Channels.Cast <ChannelElement>().Any(c => string.Compare(c.Name, channelName, true) == 0)))
                                select reportingSuite.SpecialPageLoadFunctions;

                rtnFunctions.AddRange(functions);
            }

            return(rtnFunctions.ToArray());
        }
        /// <summary>
        /// This method returns a channel name for a given folderpath. It also matches occurence
        /// of certain text in the url.
        /// </summary>
        /// <param name="urlFolderPath">This value contains the complete url</param>
        /// <returns>The channel name which matches the urlFolderPath.</returns>
        public static string GetChannelForUrlPath(string urlFolderPath)
        {
            try
            {
                WebAnalyticsOptions.Initialize();

                if (_webAnalyticsConfig.UrlPathChannelMappings != null)
                {
                    string url          = urlFolderPath.Substring(urlFolderPath.LastIndexOf('/') + 1).ToLower();
                    int    urlDelimiter = urlFolderPath.LastIndexOf('/');
                    string currUrlPath  = urlFolderPath;
                    while (!string.IsNullOrEmpty(currUrlPath))
                    {
                        var urlPathWithUrlChannelMappings = from urlPathChannel in urlPathChannelWithUrlMatchLookUp
                                                            where urlPathChannel.Key == currUrlPath && urlFolderPath.Contains(((UrlPathChannelElement)urlPathChannel.Value).UrlMatch)
                                                            select urlPathChannel;
                        if (urlPathWithUrlChannelMappings.Count() != 0)
                        {
                            return(((UrlPathChannelElement)urlPathWithUrlChannelMappings.FirstOrDefault().Value).ChannelName);
                        }

                        var urlPathChannelMappings = from urlPathChannel in urlPathChannelLookUp
                                                     where urlPathChannel.Key == currUrlPath
                                                     select urlPathChannel;

                        if (urlPathChannelMappings.Count() != 0)
                        {
                            return(((UrlPathChannelElement)urlPathChannelMappings.FirstOrDefault().Value).ChannelName);
                        }

                        // did not find, backtrack the url path to find the matching elements
                        urlDelimiter = currUrlPath.LastIndexOf('/');

                        if (currUrlPath == "/" && urlDelimiter == -1)
                        {
                            // shoud never come here, there should be the minumum '/' mapping in the web.config
                            currUrlPath = String.Empty;
                            continue;
                        }

                        currUrlPath = currUrlPath.Substring(0, urlDelimiter).ToLower();

                        //Reached the beginning of the url path or the request is for the home page.
                        //when this happens set the path '/' so the lookup can succeed. This
                        //is the final fall back.
                        if (string.IsNullOrEmpty(currUrlPath))
                        {
                            currUrlPath = "/";
                        }
                    }

                    // if it reaches here then, no mapping could be found.
                    log.InfoFormat("GetChannelForUrlPath(): No channel mapping exists for pretty url: {0}", urlFolderPath);
                }
                else
                {
                    log.Info("GetChannelForUrlPath(): Url to channel mapping information not present in config file.");
                }
            }
            catch (Exception ex)
            {
                log.Error("GetChannelForUrlPath(): Failed to process url to channel mapping", ex);
            }

            // Should never be executed.
            return("");
        }
Exemple #3
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());
        }