Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 983665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:53:44+00:00 2026-05-16T04:53:44+00:00

I have a simple, but probably common problem on how to inject HTML inside

  • 0

I have a simple, but probably common problem on how to inject HTML inside an ASP.NET MVC master page. I have a google analytics tracking code that sits on my master page. The code looks like this:

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-1']);
_gaq.push(['_trackPageview']);
// need to inject ecommerce code here
(function () {
    // google analytics code here
})();

I’m using ecommerce tracking and I want to inject the “cart” information in side this HTML on the receipt page (and ONLY on this page). So I do something like this:

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-1']);
_gaq.push(['_trackPageview']);
<% if(ViewData["googleanalytics"]!=null) {%>
<%= ViewData["googleanalytics"] %>
<% } %>
(function () {
    // google analytics code here
})();

Then in the controller, I have code that looks like this:

[HttpGet]
public ActionResult Receipt()
{
    var receipt = // get receipt model

    // get google analytics javascript. This function pulls
    // the data from the receipt model
    ViewData["googleanalytics"] = GetAnalyticsInfo(receipt); 

    return View(receipt);
}

This whole thing seems like a little bit of a kludge and I was wondering if anybody had better ideas to handle this situation?

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T04:53:45+00:00Added an answer on May 16, 2026 at 4:53 am

    Can you split the javascript into two parts:

    At the top of your master page, put:

    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-XXXXX-1']);
    _gaq.push(['_trackPageview']);
    

    At the bottom of your master page, put:

    (function () {
        // google analytics code here
    })();
    

    And then, somewhere in your receipt page’s view (where it will be output in between the two pieces of javascript from the master page), put

    <% if(ViewData["googleanalytics"]!=null) {%>
    <%= ViewData["googleanalytics"] %>
    <% } %>
    

    Worth a try?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Probably a common problem, but anyway: Let's say I have a simple entity Task
Probably something simple, but heres my problem, I have implememnted a simple captcha into
I have what is probably a really simple, studid question but I can't find
This is probably a simple question, but i have been unable to find a
Probably something really simple, but I'm having some real trouble with it. I have
this is probably too simple of a question, but here I go. I have
I have a simple problem but I am not sure how to solve it.
What I'm trying to do is quite simple but I probably have the syntax
Probably a simple question but I haven't found a solution. I have several view
this is probably simple but I'm stuck! Basically I have a parent and child

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.