ildar-shaymukhametov_grandnode-refactorings/Plugins/Grand.Plugin.Widgets.GoogleAnalytics/Views/Configure.cshtml
@{
    Layout = "_ConfigurePlugin";
}
@model Grand.Plugin.Widgets.GoogleAnalytics.Models.ConfigurationModel
@using Grand.Framework;
@await Component.InvokeAsync("StoreScopeConfiguration")
@{
    //default values
    var googleAnalytics_trackingScript = Html.Raw(System.Text.Encodings.Web.JavaScriptEncoder.Default.Encode("<!-- Google code for Analytics tracking -->" + "\r\n" +
        "<script type=\"text/javascript\">" + "\r\n" +
        "var _gaq = _gaq || [];" + "\r\n" +
        "_gaq.push(['_setAccount', '{GOOGLEID}']);" + "\r\n" +
        "_gaq.push(['_trackPageview']);" + "\r\n" +
        "{ECOMMERCE}" + "\r\n" +
        "(function() {" + "\r\n" +
        "var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;" + "\r\n" +
        "ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';" + "\r\n" +
        "var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);" + "\r\n" +
        "})();" + "\r\n" +
        "</script>"));
    var googleAnalytics_EcommerceScript = Html.Raw(System.Text.Encodings.Web.JavaScriptEncoder.Default.Encode("_gaq.push(['_addTrans', '{ORDERID}', '{SITE}', '{TOTAL}', '{TAX}', '{SHIP}', '{CITY}', '{STATEPROVINCE}', '{COUNTRY}']);" + "\r\n" +
        "{DETAILS}" + "\r\n" +
        "_gaq.push(['_trackTrans']); "));
    var googleAnalytics_EcommerceDetailScript = Html.Raw(System.Text.Encodings.Web.JavaScriptEncoder.Default.Encode("_gaq.push(['_addItem', '{ORDERID}', '{PRODUCTSKU}', '{PRODUCTNAME}', '{CATEGORYNAME}', '{UNITPRICE}', '{QUANTITY}' ]); "));

    var universalAnalytics_trackingScript = Html.Raw(System.Text.Encodings.Web.JavaScriptEncoder.Default.Encode("<!-- Google code for Analytics tracking -->" + "\r\n" +
        "<script>" + "\r\n" +
        "(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){" + "\r\n" +
        "(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o)," + "\r\n" +
        "m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)" + "\r\n" +
        "})(window,document,'script','//www.google-analytics.com/analytics.js','ga');" + "\r\n" +
        "ga('create', '{GOOGLEID}', 'auto');" + "\r\n" +
        "ga('send', 'pageview');" + "\r\n" +
        "{ECOMMERCE}" + "\r\n" +
        "</script>"));
    var universalAnalytics_EcommerceScript = Html.Raw(System.Text.Encodings.Web.JavaScriptEncoder.Default.Encode("ga('require', 'ecommerce', 'ecommerce.js');" + "\r\n" +
        "ga('ecommerce:addTransaction', {" + "\r\n" +
        "'id': '{ORDERID}'," + "\r\n" +
        "'affiliation': '{SITE}'," + "\r\n" +
        "'revenue': '{TOTAL}'," + "\r\n" +
        "'shipping': '{SHIP}'," + "\r\n" +
        "'tax': '{TAX}'" + "\r\n" +
        "});" + "\r\n" +
        "{DETAILS} " + "\r\n" +
        "ga('ecommerce:send');"));
    var universalAnalytics_EcommerceDetailScript = Html.Raw(System.Text.Encodings.Web.JavaScriptEncoder.Default.Encode("ga('ecommerce:addItem', {" + "\r\n" +
        "'id': '{ORDERID}'," + "\r\n" +
        "'name': '{PRODUCTNAME}'," + "\r\n" +
        "'sku': '{PRODUCTSKU}'," + "\r\n" +
        "'category': '{CATEGORYNAME}'," + "\r\n" +
        "'price': '{UNITPRICE}'," + "\r\n" +
        "'quantity': '{QUANTITY}'" + "\r\n" +
        "});"));
}
<script>
    $(document).ready(function () {
        $("#pre-configure-google-analytics").click(preConfigureGoogleAnalytic);
        $("#pre-configure-universal-analytics").click(preConfigureUniversalAnalytic);
    });

    function preConfigureGoogleAnalytic() {
        $('#@Html.FieldIdFor(model => model.TrackingScript)').val('@googleAnalytics_trackingScript');
        $('#@Html.FieldIdFor(model => model.EcommerceScript)').val('@googleAnalytics_EcommerceScript');
        $('#@Html.FieldIdFor(model => model.EcommerceDetailScript)').val('@googleAnalytics_EcommerceDetailScript');
    }

    function preConfigureUniversalAnalytic() {
        $('#@Html.FieldIdFor(model => model.TrackingScript)').val('@universalAnalytics_trackingScript');
        $('#@Html.FieldIdFor(model => model.EcommerceScript)').val('@universalAnalytics_EcommerceScript');
        $('#@Html.FieldIdFor(model => model.EcommerceDetailScript)').val('@universalAnalytics_EcommerceDetailScript');
    }
</script>
<form asp-controller="WidgetsGoogleAnalytics" asp-action="Configure" method="post">
    
    <div class="form-horizonal">
        <div class="form-body">
            <div class="form-group">
                <div class="note note-info">
                    <p>
                        Google Analytics is a free website stats tool from Google. It keeps track of statistics
                        about the visitors and ecommerce conversion on your website.
                    </p>
                    <p>
                        Follow the next steps to enable Google Analytics integration:
                    </p>
                    <ul>
                        <li>
                            <a href="http://www.google.com/analytics/" target="_blank">
                                Create a Google Analytics
                                account
                            </a> and follow the wizard to add your website
                        </li>
                        <li>Copy the Tracking ID into the 'ID' box below</li>
                        <li>Click the 'Save' button below and Google Analytics will be integrated into your store</li>
                    </ul>
                    <p>
                        If you would like to switch between Google Analytics (used by default) and Universal Analytics, then please use the buttons below:
                    </p>
                    <input type="button" id="pre-configure-google-analytics" class="k-button" value="Pre-configure Google Analytics" />
                    <input type="button" id="pre-configure-universal-analytics" class="k-button" value="Pre-configure Universal Analytics" />
                </div>
            </div>
            <div class="form-group">
                <div class="col-md-4 col-sm-4 text-right">
                    @Html.OverrideStoreCheckboxFor(model => model.GoogleId_OverrideForStore, model => model.GoogleId, Model.ActiveStoreScopeConfiguration)
                    <admin-label asp-for="GoogleId" class="control-label" />
                </div>
                <div class="col-md-8 col-sm-8">
                    <admin-input asp-for="GoogleId" />
                    <span asp-validation-for="GoogleId"></span>
                </div>
            </div>
            <div class="form-group">
                <div class="col-md-4 col-sm-4 text-right">
                    @Html.OverrideStoreCheckboxFor(model => model.TrackingScript_OverrideForStore, model => model.TrackingScript, Model.ActiveStoreScopeConfiguration)
                    <admin-label asp-for="TrackingScript" class="control-label" />
                </div>
                <div class="col-md-8 col-sm-8">
                    <admin-textarea asp-for="TrackingScript"></admin-textarea>
                    <span asp-validation-for="TrackingScript"></span>
                </div>
            </div>
            <div class="form-group">
                <div class="col-md-4 col-sm-4 text-right">
                    @Html.OverrideStoreCheckboxFor(model => model.EcommerceScript_OverrideForStore, model => model.EcommerceScript, Model.ActiveStoreScopeConfiguration)
                    <admin-label asp-for="EcommerceScript" class="control-label" />
                </div>
                <div class="col-md-8 col-sm-8">
                    <admin-textarea asp-for="EcommerceScript"></admin-textarea>
                    <span asp-validation-for="EcommerceScript"></span>
                </div>
            </div>
            <div class="form-group">
                <div class="col-md-4 col-sm-4 text-right">
                    @Html.OverrideStoreCheckboxFor(model => model.EcommerceDetailScript_OverrideForStore, model => model.EcommerceDetailScript, Model.ActiveStoreScopeConfiguration)
                    <admin-label asp-for="EcommerceDetailScript" class="control-label" />
                </div>
                <div class="col-md-8 col-sm-8">
                    <admin-textarea asp-for="EcommerceDetailScript"></admin-textarea>
                    <span asp-validation-for="EcommerceDetailScript"></span>
                </div>
            </div>
            <div class="form-group">
                <div class="col-md-4 col-sm-4 text-right">
                    @Html.OverrideStoreCheckboxFor(model => model.IncludingTax_OverrideForStore, model => model.IncludingTax, Model.ActiveStoreScopeConfiguration)
                    <admin-label asp-for="IncludingTax" class="control-label" />
                </div>
                <div class="col-md-8 col-sm-8">
                    <label class="mt-checkbox mt-checkbox-outline control control-checkbox">
                        <admin-input asp-for="IncludingTax" />
                        <div class="control__indicator"></div>
                    </label>
                    <span asp-validation-for="IncludingTax"></span>
                </div>
            </div>
            <div class="form-group">
                <div class="col-md-4 col-sm-4 text-right">
                    @Html.OverrideStoreCheckboxFor(model => model.AllowToDisableConsentCookie_OverrideForStore, model => model.AllowToDisableConsentCookie, Model.ActiveStoreScopeConfiguration)
                    <admin-label asp-for="AllowToDisableConsentCookie" class="control-label" />
                </div>
                <div class="col-md-8 col-sm-8">
                    <label class="mt-checkbox mt-checkbox-outline control control-checkbox">
                        <admin-input asp-for="AllowToDisableConsentCookie" />
                        <div class="control__indicator"></div>
                    </label>
                    <span asp-validation-for="AllowToDisableConsentCookie"></span>
                </div>
            </div>
            <div class="form-group">
                <div class="col-md-4 col-sm-4 text-right">
                    @Html.OverrideStoreCheckboxFor(model => model.ConsentDefaultState_OverrideForStore, model => model.ConsentDefaultState, Model.ActiveStoreScopeConfiguration)
                    <admin-label asp-for="ConsentDefaultState" class="control-label" />
                </div>
                <div class="col-md-8 col-sm-8">
                    <label class="mt-checkbox mt-checkbox-outline control control-checkbox">
                        <admin-input asp-for="ConsentDefaultState" />
                        <div class="control__indicator"></div>
                    </label>
                    <span asp-validation-for="ConsentDefaultState"></span>
                </div>
            </div>
            <div class="form-group">
                <div class="col-md-4 col-sm-4 text-right">
                    @Html.OverrideStoreCheckboxFor(model => model.ConsentName_OverrideForStore, model => model.ConsentName, Model.ActiveStoreScopeConfiguration)
                    <admin-label asp-for="ConsentName" class="control-label" />
                </div>
                <div class="col-md-8 col-sm-8">
                    <admin-textarea asp-for="ConsentName"></admin-textarea>
                    <span asp-validation-for="ConsentName"></span>
                </div>
            </div>
            <div class="form-group">
                <div class="col-md-4 col-sm-4 text-right">
                    @Html.OverrideStoreCheckboxFor(model => model.ConsentDescription_OverrideForStore, model => model.ConsentDescription, Model.ActiveStoreScopeConfiguration)
                    <admin-label asp-for="ConsentDescription" class="control-label" />
                </div>
                <div class="col-md-8 col-sm-8">
                    <admin-textarea asp-for="ConsentDescription"></admin-textarea>
                    <span asp-validation-for="ConsentDescription"></span>
                </div>
            </div>
            <div class="form-group">
                <div class="col-md-12 col-sm-12">
                    <div class="note note-info">
                        <em>Please note that {ECOMMERCE} line works only when you have "Disable order completed page" order setting unticked.</em>
                    </div>
                </div>
            </div>
        </div>
        <div class="form-actions">
            <div class="offset-md-3 offset-sm-3 col-md-9 col-sm-9">
                <input type="submit" name="save" class="btn green" value="@T("Admin.Common.Save")" />
            </div>
        </div>
    </div>
</form>
