コード例 #1
0
        public void GetWebAnalytics()
        {
            IPageAssemblyInstruction pageAssemblyInfo = null;

            pageAssemblyInfo = InitializeTestPageAssemblyInfo();
            WebAnalyticsSettings webAnalyticsSettings = null;

            webAnalyticsSettings = pageAssemblyInfo.GetWebAnalytics();
            Assert.IsNotNull(webAnalyticsSettings);
            Assert.IsTrue(webAnalyticsSettings.Props.Count > 0);
            Assert.IsTrue(webAnalyticsSettings.Evars.Count > 0);
        }
コード例 #2
0
        /// <summary>
        /// Uses the WebAnalyticsPageLoad helper class to render the required omniture java script
        /// for Web Analytics.
        /// </summary>
        /// <param name="output">HtmlTextWriter object</param>
        protected override void RenderContents(HtmlTextWriter output)
        {
            base.RenderContents(output);
            IPageAssemblyInstruction pgInstruction        = PageAssemblyContext.Current.PageAssemblyInstruction;
            WebAnalyticsSettings     webAnalyticsSettings = pgInstruction.GetWebAnalytics();
            string configChannelName = "";

            // If web analytics are present, create a new instance of WebAnalyticsPageload,
            // set its variables, and use those to draw the analytics HTML.
            if (webAnalyticsSettings != null)
            {
                WebAnalyticsPageLoad webAnalyticsPageLoad = new WebAnalyticsPageLoad();
                webAnalyticsPageLoad.SetLanguage(PageAssemblyContext.Current.PageAssemblyInstruction.GetField("language"));

                // Use pretty url to get channel name from the mapping, mapping information is in web.config
                string prettyUrl = pgInstruction.GetUrl("PrettyUrl").UriStem;
                if (!string.IsNullOrEmpty(prettyUrl))
                {
                    configChannelName = WebAnalyticsOptions.GetChannelForUrlPath(prettyUrl);
                }

                // Get the channel name from the section details. As of the cancer.gov Feline release, analytics channels
                // are set in the navons, not Web.config. The old functionality is being used in the catch block for now.
                try
                {
                    string        sectionPath = pgInstruction.SectionPath;
                    SectionDetail detail      = SectionDetailFactory.GetSectionDetail(sectionPath);
                    string        channelName = WebAnalyticsOptions.GetChannelsFromSectionDetail(detail);
                    webAnalyticsPageLoad.SetChannel(channelName);
                    webAnalyticsPageLoad.SetReportSuites(detail);
                }
                catch (Exception ex)
                {
                    log.Warn("RenderContents(): Error retrieving analytics channel.", ex);
                    webAnalyticsPageLoad.SetChannel(configChannelName);
                }

                foreach (KeyValuePair <WebAnalyticsOptions.eVars, string> kvp in webAnalyticsSettings.Evars)
                {
                    webAnalyticsPageLoad.AddEvar(kvp.Key, kvp.Value);
                }

                foreach (KeyValuePair <WebAnalyticsOptions.Events, string> kvp in webAnalyticsSettings.Events)
                {
                    webAnalyticsPageLoad.AddEvent(kvp.Key);
                }

                foreach (KeyValuePair <WebAnalyticsOptions.Props, string> kvp in webAnalyticsSettings.Props)
                {
                    webAnalyticsPageLoad.AddProp(kvp.Key, kvp.Value);
                }

                // Draw the control HTML based on the control ID
                switch (this.ID)
                {
                // Draw analytics HTML data element
                case "WebAnalyticsData":
                    webAnalyticsPageLoad.DrawAnalyticsDataTag(output);
                    break;

                // Draw s_code script block
                // This should NOT be used once DTM Analytics are in place
                case "WebAnalyticsControl1":
                case "WebAnalyticsLegacy":
                    output.Write(webAnalyticsPageLoad.Tag());
                    break;

                default:
                    break;
                }
            }
        }