Esempio n. 1
0
        private void IncludeAnalyticsScript()
        {
            /* render something similiar to:
             *      <script async src="https://www.googletagmanager.com/gtag/js?id=UA-108221738-1"></script>
             * <script>
             * window.dataLayer = window.dataLayer || [];
             * function gtag(){dataLayer.push(arguments);}
             * gtag('js', new Date());
             *
             * gtag('config', '@RemeWebConstants.GOOGLE_ANALYTICS_TRACKING_ID');
             * </script>
             */
            StringBuilder sb = new StringBuilder();

            sb.AppendLine($@"<script>");
            sb.AppendLine($@"(function(i,s,o,g,r,a,m){{i['GoogleAnalyticsObject'] = r;i[r]=i[r]||function(){{");
            sb.AppendLine($@"(i[r].q=i[r].q||[]).push(arguments)}},i[r].l=1*new Date();a=s.createElement(o),");
            sb.AppendLine($@"m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)");
            sb.AppendLine($@"}})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');");
            sb.AppendLine($@"ga('create', 'UA-{_trackingId}-1', 'auto');");
            sb.AppendLine($@"ga('send', 'pageview');");
            if (_isTrackByUser && Thread.CurrentPrincipal.Identity.IsAuthenticated)
            {
                sb.AppendLine($@"ga('set', 'userId', '{Thread.CurrentPrincipal.Identity.Name}'); // Set the user ID using signed-in user_id.");
            }


            sb.AppendLine($@"</script>");
            PartialViewsDependancies.GetFromRequest().AddStyle(sb.ToString());
        }
Esempio n. 2
0
        private void IncludeRecaptcha()
        {
            /* render something similiar to:
             *       <script type="text/javascript">
             *              var onloadCallback = function() {
             *                  grecaptcha.render('div-recaptcha', { 'sitekey': '@Settings.ReCaptchaSiteKey' });
             *              };
             *      </script>
             */
            StringBuilder sb = new StringBuilder();

            sb.AppendLine($@"<script type=""text/javascript"">");
            sb.AppendLine($@"var onloadCallback = function() {{");
            sb.AppendLine($@"grecaptcha.render('div-recaptcha', {{ 'sitekey': '{_siteKey}' }});");
            sb.AppendLine($@"}};");
            sb.AppendLine($@"</script>");
            PartialViewsDependancies.GetFromRequest().AddStyle(sb.ToString());

            string language           = CreaDev.Framework.Core.Culture.GetThreadLanguageValue();
            string scriptBottomOfPage =
                $@"<script src=""https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit&hl={
                        language
                    }"" async defer> </script>";

            PartialViewsDependancies.GetFromRequest().AddScript(scriptBottomOfPage);
        }