0

I was asked to capture the analytics on a website. The website is made up of 5 web pages, but I now realize that the domain is the same and the only thing that changes is the URL fragment, i.e. www.domain.com#a, www.domain.com#b. The only info that comes through to GA is the domain and it does not include the URL fragments. The tracking code I'm using is Tealium and the data is being sent back to Google Analytics. How can I set this up so that i can see the entire URL in GA including the URL fragments?

ImASkuller
  • 39
  • 5

1 Answers1

0

So, from Tealium's perspective we need to trigger a view event when a new fragment is loaded (if I am understanding this correctly).

If we assume that the fragment change occurs on a link click then we need to trigger the view event when the link click occurs.

From the GA perspective, we need to trigger a view that captures the new information. For a view this is likely to be location, path and title.

Therefore, we need Tealium to construct the new data points and then pass them in a view event to GA.

The simplest way to do this in Tealium (all things being equal) is via a jQuery onHandler Extension

The jQuery extension requires the following information:

  1. jQuery selector (or selectors) to pay attention to
  2. "Trigger On" event type (this will be Click in this example)
  3. Tracking event type to run (View event in this case)
  4. Variable & values to set Tealium jQuery onHandler extension config
  5. note it's always a good idea to set a condition on your jQuery extensions so that they only run when needed instead of all the time and everywhere

In this extension, I have set the following:

  1. jQuery Selector: '#MyID_1, #MyID_2, #MyID_3' -- yes you can pass a list of selectors or nearly any other valid jQuery selector statement
  2. Trigger On: 'click'
  3. Tracking Event: 'view'
  4. 3 Variables:

    a. 'page_name' : $(this).text(); //get the link text

    b. 'my_url' : utag.data['dom.url']+$(this).attr('href') //building the full URL including the fragment //utag.data['dom.url'] is a variable/datapoint that Tealium automatically generates

    c. my_path : utag.data['dom.pathname']+$(this).attr('href'); //building the path //utag.data['dom.pathname'] is a variable/datapoint that Tealium automatically generates

NOTE: make sure to set the type for each these to "JS Code" otherwise your JavaScript will be quoted out as a string.

Why these three variables? As I understand GA, these are the values it would expect for a new page view -- location/URL, path, and Title so we are constructing those values in the extension to pass them to GA on the view event.

Now, we just need to map these new variables to GA.

  1. my_path gets mapped to page in the GA mapping toolbox
  2. page_name gets mapped to title
  3. location isn't a default option in the mapping toolbox so we need to add a custom destination variable called location and map my_url to it. custom variable mapping for GA

That's how you do it from within Tealium and minimal coding. If for some reason you don't want to / can't do it inside of Tealium, this provides us with a very nice template for a custom function to add to our codebase:

`$(document.body).on('click', '#altID', function(){
     utag.view({
         "page_name": $(this).text(),
         "my_url": utag.data['dom.url'] + $(this).attr('href'),
         "my_path": utag.data['dom.pathname'] + $(this).attr('href')
     })
})`

See both in action over here at CodePen.

Clint
  • 16
  • 2
  • Thank you for your thorough response. Unfortunately, I cant do it inside Tealium. So the second option is the best one for me. I want to see this in action. When I go to CodePen what am I looking for. I'm just clicking on those buttons to see the full URL that pops up? Do I just ad this javascript function to each page of the website. This will send the full URL (including the fragment) back to Tealium and then Tealium sends it over to Google Analytics? – ImASkuller Jan 23 '19 at 23:18
  • Easiest way to see it in action is to open the dev tools and watch the network panel when you click on the button labeled 'utag.view'. then watch for the GA request (easily identifiable by the collect? path. Look at the dl, dt an dp querystrings. If you have Tealium Tools installed, I recommend getting the UTAG Debugger tool which can also be very helpful. – Clint Jan 24 '19 at 00:07
  • Tealium also has several native libraries (so for instance, if your single page app is built on angular, there is a library for it) https://github.com/Tealium – Clint Jan 24 '19 at 00:12
  • [List of Tealium Tools](https://community.tealiumiq.com/t5/Developer-Tools/List-of-Custom-Tealium-Tools/ta-p/23066) – Clint Jan 24 '19 at 00:29
  • so the native utag view works on a page load and not just by clicking on a link - correct? This will automatically send the full path to GA upon page view? – ImASkuller Jan 24 '19 at 17:07
  • @ImASkuller, just to clarify, unless you set a config override, utag.js will execute a view event on page load that collects (and sends as appropriate for a given tag) information from the DOM like referrer, location, pathname, etc. Fragments, though collected, aren't sent by default. The utag.view function I have coded in the example is only initiated on click of the relevant button. let me know if that answers your question. For more information on the [UTAG order of operations, check out this article.](https://community.tealiumiq.com/t5/iQ-Tag-Management/Order-of-Operations/ta-p/326) – Clint Jan 24 '19 at 18:29
  • The most important thing for me is to distinguish between each page (really each hashtag) when the data is sent to GA. So this is code that would be linked up to each button. Let me ask you this - would GA distinguish these pages if each hashtag had its own Page Title? – ImASkuller Jan 24 '19 at 19:09
  • Yes, you will get a unique view per page title, BUT this is likely to cause problems on the analysis side because the URL (location) isn't changing from GA's point of view unless you also build and pass a new URL that contains the fragment – Clint Jan 24 '19 at 19:46
  • So, it sounds like Page Title might be an option if analyze based on Page Title, but I'll put that on the backburner. I want to go with your solution which seems like the best way to go. So I want to understand this better. – ImASkuller Jan 24 '19 at 21:05
  • Lets say I have index.com#index, index.com#about, and index.com#contact. I am user and I go to the first page which is index.com#index. As a user I haven't clicked a button yet so this code is not going to trigger until a button is clicked - correct. So since no button was clicked what will come back to GA is just index.com. Now the user clicks on the About button and then that will trigger this function and what will come back to GA is index.com#about. Is that correct? I'm almost there with you - just help me a little bit more. Thanks! – ImASkuller Jan 24 '19 at 21:09
  • Hey @ImASkuller, no worries -- happy to help. You are almost there! First step is correct --> user lands at index.com#index google will see it as index.com. When the user clicks on index.com#about button, nothing is going to happen in GA (because the url does not change or reload) until we intervene via the utag.view function. If all we pass is page title then GA will record a new view for that Title BUT the url will just be index.com because the fragments are not passed naturally. IF you want the URL (not title) to contain the fragment then you need to construct a new URL – Clint Jan 24 '19 at 21:24
  • OK. so I took the example code you gave me and incorporated into my own test page so I can see the results on GA. Below is the code; – ImASkuller Jan 24 '19 at 22:49
  • document.cookie="utagdb=true"; (function(a,b,c,d) { a='thiswouldbethetrackingcode.js'; b=document;c='script';d=b.createElement(c);d.src=a;d.type='text/java'+c;d.async=true; a=b.getElementsByTagName(c)[0];a.parentNode.insertBefore(d,a); } )();

    Tealium URL Fragment Example

    – ImASkuller Jan 24 '19 at 22:52
  • – ImASkuller Jan 24 '19 at 22:53
  • i broke it up into 2 chunks of code. Can you take a look at this? When I click on the native utag.view button I'm looking at the realtime results in GA and I don't see a change in the url. – ImASkuller Jan 24 '19 at 22:53
  • Hey @ImASkuller are you seeing no view at all or you get a new view for ‘native utag.view’ but the URL is not updating? If the former, is jQuery loaded on your test page? – Clint Jan 24 '19 at 23:33
  • @ImASkuller any chance your test page is accessible? – Clint Jan 24 '19 at 23:36
  • @ImASkuller the two most likely issues are 1) jquery library is not loaded (no view at all) or 2) you haven't mapped 'my_url' to 'location' in the GA tag (view is recorded but URL does not update for new view) – Clint Jan 24 '19 at 23:47
  • Unfortunately, this is all being done within my works network so it’s not accessible. I’m not doing the query option just the native utag.view option. I don’t have access to the tealium. I’m just using the tealium code. So I should be mapping within GA? – ImASkuller Jan 25 '19 at 00:03
  • I'm a bit confused but assuming that the jQuery library IS loaded on your test page. Otherwise the on click function I provided wouldn't work on your test page at all. So, the issue is that the GA tag in Tealium does not have the proper data mappings to resolve all of your challenges. [take a look at this](https://i.stack.imgur.com/MtsaA.png) to see what work has to happen inside of Tealium for this to all work out. Because you are seeing the new view but not the updated URL we can assume that page_name is already mapped to title in GA. – Clint Jan 25 '19 at 00:20
  • I understand what you’re saying about mapping. But I can’t get into Tealium to do that. I just have the tealium tracking code and GA. Is there any way to do this without going into Tealium? – ImASkuller Jan 25 '19 at 00:28
  • The required vars and objects are locally scoped within the Tealium GA tag so not accessible from the page. So the only way to get updated mapping for the tag is through the Tealium interface. – Clint Jan 25 '19 at 01:07
  • So, thanks for your help. I will see if I can have the administrator of Tealium provide me with those mappings. If not, then I will use the GA tracking code instead of Tealium. I know how to do this with GA. You definitely steered me in the right direction here. Thanks again. – ImASkuller Jan 25 '19 at 02:21