Google Analytics trackEvent is the foundation of every website's analytics strategy

I've been experimenting with Google Analytics in a unique way and I'll do my best to explain it here.

On my holding site, I'm loading a form using jQuery. The main site has its own tracking code while the ajax loaded content uses a different tracking code, and surprisingly, everything is functioning well.

_gat._createTracker('UA-XXXXXXXX-2', 'myTracker');
var _gaq = _gaq || [];
_gaq.push(['myTracker._setAccount', 'UA-XXXXXXXX-2']);

The form consists of multiple parts and for each completed part, I send a page track event with a custom URL, which also seems to be working smoothly.

_gaq.push(['myTracker._trackPageview', '/form/stage1/']);

However, I'm facing an issue with tracking events for changes within the form (such as dropdown selections). While the events are visible in Google Analytics, they all show up under "/" instead of "/form/stage1/", probably because it's coming from the main site where the form is embedded.

_gaq.push(['myTracker._trackEvent', 'Sample', ddValue]);

So my question is, can I specify a different page URL for the _trackEvent function to track against?

Thank you in advance.

Answer №1

There isn't a direct connection between _trackEvent and the most recent _trackPageview. The former always utilizes

location.pathname+location.search
, regardless of any custom value passed by the latter.

You can make use of the "Category" and "Action" fields in the Event, but don't forget about the "Label" field where you can pass additional values.

_gaq.push(['myTracker._trackEvent', 'Sample', ddValue, "/form/stage/1"]);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Dojo - "Attempting to register widget with the ID centerPane, only to find that ID has already been taken."

I'm encountering an issue with a content pane in Dojo where it briefly appears with the content before disappearing. The error message I receive is: Uncaught ReferenceError: dijit is not defined index.php:22 dojo/parser::parse() error Er ...

Utilize jQuery to substitute numbers with strings through replacement

My question pertains to the topic discussed here. I am looking for a more refined jQuery replacement function that can substitute a number with a string. My PHP script returns numbers in the format of 1.27 Based on a specified range, these numbers need ...

Combine object attributes to create a new column in a table

Check out this plunker I created. What is the most efficient way to merge the contents of $scope.blacklist into $scope.friends when ng-click="showColumn('Blacklist');" is triggered, and also add a new column named Coming to the table. Ng-App &am ...

In order for Javascript to continue, it must first wait for a request to be completed

I have a beginner question that's been on my mind. I'm currently working on creating a wrapper for an API and I need to authenticate to receive the access token for further requests (please note, the API doesn't use OAuth). Here is a simpli ...

When using the "Content-Disposition" header with the value "inline;filename=" + fileName, it does not necessarily guarantee that PDF files will be displayed directly

When a link is clicked, I want the PDF file to first show in a new tab as a preview before allowing users to download it. I researched and found advice suggesting that including these two headers would achieve this: Response.AddHeader("Content-Dispositio ...

What are the steps to manipulate the data within an EJS file after passing an array through Node.js as an object?

I'm currently developing a simple calendar application using Node.js and ejs. I am working on passing an array of months through express to my ejs file, with the goal of being able to cycle through each month by clicking the next button. How can I imp ...

Retrieving HTML content from Wikipedia's API using JavaScript

I am encountering an issue where every time I attempt to log data to my console, an error occurs. Could someone kindly point out what may be the problem with the code? My objective is to actually showcase the html content on a webpage. Below is the code ...

Fabric.js Textbox does not automatically wrap long text in version 5.3.0

I am currently using fabric.js version 5.3.0. The Textbox object in fabric.js will wrap text when you add space between words, but it won't wrap when you add text without any spaces. Please take a look at the following fiddle: https://jsfiddle.net/N ...

Guide to invoking a bootstrap modal dynamically within a loop with the help of jQuery

I'm currently facing an issue with my code that involves inserting data into a database. The code is set up to check if the data already exists, and if it does, prompt the user with a Bootstrap modal to confirm whether they want to continue adding the ...

Why is my `$http` data not being sent in Angular JS?

Within my controller, I am initiating an http request as shown below: var postData = { action: 'getTasksByProjectSlug', slug: 'inbox' } $http({ url: 'http://localhost/toodloo/api/kernel.php', method: 'POST' ...

How to add a gradient background in the most recent version of chart.js?

I came across a question about implementing gradients with the latest version of chart.js. I attempted to replicate it in this demo, but the gradient settings seemed to be ineffective. Do you have any suggestions on how to make it work? Below is the comp ...

"Trouble with jquery .load() function not working in older versions of IE (internet explorer

I've been searching for a solution all day, but I'm still encountering this error. We have an Expression Engine setup for a client and we are trying to implement ajax-navigation. We are using the default $.load() function which is working perfec ...

The issue with npm run build may be caused by a compatibility issue between TypeScript and lodash

Currently using typescript version 4.5.2 and lodash version 4.17.21 Running the command npm run build will trigger tsc && react-scripts build The following errors were encountered during the build process: node_modules/@types/lodash/common/objec ...

Performing a reverse image search request using Javascript/AJAX to query Google

I have been attempting to perform a reverse image search request using AJAX, but I keep receiving 302 errors. After checking the Firebug console, I discovered that the response header from Google contains a URL linking me to the results. However, I am unsu ...

Using jQuery to extract the HTML content of an element while removing the style attribute

Is there a way to retrieve the raw HTML of an element, or obtain the HTML without the "style" attribute applied? Let's consider the example below: <div class="outer"> <div class="inner"> some text </div> </div> A ...

Automatically collapse the Bootstrap4 Dropdown Menu upon clicking the select element

After tackling my previous issue on Stack Overflow, I stumbled upon a new question that has been bothering me. The problem arises when users click on the arrow to reveal advanced search options, as the form drops down as expected. However, when a user cli ...

Pass props to child components in Vue.js based on certain conditions

Here's an example of conditionally sending props to the Quantity component. <v-card class="mx-auto" max-width="344" shaped v-for="(item, index) in allItems || orderedItems" :key="index" > <Quantit ...

Optimal approach to displaying views with Express.js and EJS

Recently, I came across a website that only renders EJS templates using Express.js routing. All the routes are defined in the /routes/index.js file. As the file grows with more routes being added, I am thinking about restructuring it to make it more develo ...

Tips on retrieving ajax variable in php

I'm facing an issue with passing the ajax variable to a php page. While I can successfully alert and display the value, sending it to the php page for deletion is not working as expected. Below is the code I've implemented: AJAX code: functio ...

Tips on displaying information following the parsing of JSON

Trying to retrieve a list of users using this code snippet <div id="users" data-users='[{"name":"one","userName":"user_one"}, {"name":"two","userName":"user_two&q ...