Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.
C# aspnet-corecsharpdockerdotnetecommerceecommerce-platformmongodbmulti-storemulti-vendornosqlonline-shopshoppingcart
@{
Layout = "_AdminLayout";
ViewBag.Title = Loc["Widgets.GoogleAnalytics.FriendlyName"];
}
@using System.Text.Encodings.Web
@model Widgets.GoogleAnalytics.Models.ConfigurationModel
@{
//default values
var googleAnalytics_trackingScript = Html.Raw(JavaScriptEncoder.Default.Encode(@"<!-- Google tag (gtag.js) -->
<script async src='https://www.googletagmanager.com/gtag/js?id={GOOGLEID}'></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '{GOOGLEID}');
{ECOMMERCE}
</script>
"));
var googleAnalytics_EcommerceScript = Html.Raw(JavaScriptEncoder.Default.Encode("gtag('event', 'purchase', {transaction_id: '{ORDERID}', value: {TOTAL}, tax: {TAX}, shipping: {SHIP}, currency: '{CURRENCY}', city: '{CITY}', state: '{STATEPROVINCE}', country: '{COUNTRY}', items: [{DETAILS}]});"));
var googleAnalytics_EcommerceDetailScript = Html.Raw(JavaScriptEncoder.Default.Encode("{ item_id: '{PRODUCTID}', item_name: '{PRODUCTNAME}', item_category: '{CATEGORYNAME}', price: {UNITPRICE}, quantity: {QUANTITY} }, "));
}
<script>
$(document).ready(function () {
$("#pre-configure-google-analytics").click(preConfigureGoogleAnalytic);
});
function preConfigureGoogleAnalytic() {
$('#@Html.IdFor(model => model.TrackingScript)').val('@googleAnalytics_trackingScript');
$('#@Html.IdFor(model => model.EcommerceScript)').val('@googleAnalytics_EcommerceScript');
$('#@Html.IdFor(model => model.EcommerceDetailScript)').val('@googleAnalytics_EcommerceDetailScript');
}
</script>
@* the setup steps stay a note; the id and the scripts in one card, with the pre-configure button
(which fills the three scripts) in its header; the cookie consent in another card. Save is the
one primary action instead of the _ConfigurePlugin chrome *@
<form asp-controller="WidgetsGoogleAnalytics" asp-action="Configure" method="post">
<admin-page title="@Loc["Widgets.GoogleAnalytics.FriendlyName"]" icon="bi-graph-up">
<page-actions>
<button type="submit" name="save" class="btn btn-primary">
<i class="bi bi-check-lg"></i> @Loc["Admin.Common.Save"]
</button>
</page-actions>
@await Component.InvokeAsync("StoreScope")
<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>
</div>
<admin-card>
<card-actions>
<input type="button" id="pre-configure-google-analytics" class="btn btn-outline-secondary btn-sm" value="Pre-configure Google Analytics"/>
</card-actions>
<div class="grand-fields">
<admin-field asp-for="GoogleId" size="lg"/>
<admin-field asp-for="TrackingScript">
<admin-textarea asp-for="TrackingScript"></admin-textarea>
</admin-field>
<admin-field asp-for="EcommerceScript">
<admin-textarea asp-for="EcommerceScript"></admin-textarea>
</admin-field>
<admin-field asp-for="EcommerceDetailScript">
<admin-textarea asp-for="EcommerceDetailScript"></admin-textarea>
</admin-field>
<admin-field asp-for="IncludingTax"/>
</div>
<div class="note note-info mt-3">
<em>Please note that {ECOMMERCE} line works only when you have "Disable order completed page" order setting unticked.</em>
</div>
</admin-card>
<admin-card>
<div class="grand-fields grand-fields--2col">
<admin-field asp-for="AllowToDisableConsentCookie"/>
<admin-field asp-for="ConsentDefaultState"/>
<admin-field asp-for="ConsentName">
<admin-textarea asp-for="ConsentName"></admin-textarea>
</admin-field>
<admin-field asp-for="ConsentDescription">
<admin-textarea asp-for="ConsentDescription"></admin-textarea>
</admin-field>
</div>
</admin-card>
</admin-page>
</form>