简体   繁体   中英

Google Analytics - Custom Value for “dl” Parameter

I'm using Google Analytics (gtag version) on my site, and am trying to prevent actual urls from being sent to Google Analytics. Specifically, I see the dl parameter contains the url:

在此处输入图像描述

QUESTION: How can I customize the value of the dl parameter?

My current setup is as follows (I'm testing locally, by the way). In the head, I've included the standard Google Analytics gtag code, with a few custom fields:

<script async src="https://www.googletagmanager.com/gtag/js?id=<TRACKING_ID>"></script>
<script>
    window.dataLayer = window.dataLayer || [];
    function gtag() { dataLayer.push(arguments); }
    gtag('js', new Date());
    gtag('config', '<TRACKING_ID>', {
        'custom_map': {
            'metric1': 'time_to_interactive',
            'metric2': 'dom_content_loaded_in',
            'metric3': 'dom_completely_loaded',
            'dimension1': 'time_to_interactive',
            'dimension2': 'dom_content_loaded_in',
            'dimension3': 'dom_completely_loaded'
        }
    });
</script>

And then in a body load function, I have the following code:

window.gtag('event', 'load', {
    'event_category': 'CriticalRenderingPath',
    'event_label': document.title, //url,
    'time_to_interactive': millisToHumanFormat(interactive),
    'dom_content_loaded_in': millisToHumanFormat(dcl),
    'dom_completely_loaded': millisToHumanFormat(complete)
});

Google Analytics developer documentation is pretty inconsistent and terrible, and I was not able to find a clear answer there. On the old system (ga.js), according to this , you can say:

ga('set', 'location', 'CUSTOM_VALUE_HERE');

But I have no idea how to do it using the new gtag version of Google Analytics. I've tried a similar thing - in fact I tried all of these:

gtag('set', {
  'pageview': 'TEST_PAGE',
  'dl': 'TEST_DL_PAGE',
  'location': 'TEST_LOCATION',
  'page': 'TEST_PAGE',
  'documentlocation': 'TEST_LOCATION',
  'documentLocation': 'TEST_LOCATION',
  'document-location': 'TEST_LOCATION',
  'document_location': 'TEST_LOCATION'
});
gtag('set', 'location', 'TEST_LOCATION');
gtag('set', 'pageview', 'TEST_LOCATION');
gtag('set', 'dl', 'TEST_LOCATION');
gtag('set', 'page', 'TEST_LOCATION');
gtag('set', 'documentlocation', 'TEST_LOCATION');
gtag('set', 'documentLocation', 'TEST_LOCATION');
gtag('set', 'document-location', 'TEST_LOCATION');
gtag('set', 'document_location', 'TEST_LOCATION');

Nothing works.

Use page_location in your config as listed here, https://developers.google.com/analytics/devguides/collection/gtagjs/pages

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM