Same origin setup with Nginx - no requests in server preview

Hi,

we setup a same-origin usin Nginx for rerouting, but for some reason I only see requests in the server preview if I enable preview header power up. Otherwise it seems like both preview windows are not properly synced and the server preview window doesn’t recoginse events sent from the web preview window.

Our Nginx configuration is as follows:

    # custom GTM
    location = /stag { return 302 /stag/; }
    location ~ ^/stag(.*) {
        resolver 8.8.8.8 valid=3600s;
        proxy_pass https://stag.jelovica.com$1$is_args$args;
        proxy_set_header Host stag.jelovica.com;
        proxy_set_header X-From-Cdn "cf-stape";
        proxy_set_header CF-Connecting-Ip $remote_addr;
    }

I also tried to manually add a line for gtm preview header, but I don’t know if this is correct:

proxy_set_header X-Gtm-Server-Preview $http_x_gtm_server_preview;

Is this a specific behavior for Nginx setup that I don’t see requests unless I turn the preview header power up?

This is one of the requests from Stape Log that I think is received by the server but not shown in the rpeview as it doesn’t contain request_X-Gtm-Server-Preview

{
  "id": "1748436965237185555",
  "date": 1748436965,
  "traceId": "8e66bb13-faf8-4623-9a4b-34f1f0063191",
  "type": {
    "type": "access",
    "label": "Access Log"
  },
  "client": {
    "type": "GA",
    "label": "GA4"
  },
  "event": {
    "type": "PageView",
    "label": "Page View"
  },
  "responseStatusCode": "200",
  "requestUrl": "https://stag.jelovica.com/g/collect?v=2&tid=G-00BPL66LPS&gtm=45je55q0v9100280165z89209721418za204zb9209721418&_p=1748436963058&_dbg=1&gcs=G111&gcd=13r3r3r2r5l1&npa=0&dma_cps=syphamo&dma=1&tag_exp=101509157~103116026~103130498~103130500~103200004~103233427~103252644~103252646~104481633~104481635&ptag_exp=101509157~103116026~103130498~103130500~103200004~103233427~103252644~103252646~104481633~104481635&cid=471502747.1748435063&ecid=1217857293&ul=sl-si&sr=1920x1080&ur=SI&uaa=x86&uab=64&uafvl=Chromium%3B136.0.7103.114%7CGoogle%2520Chrome%3B136.0.7103.114%7CNot.A%252FBrand%3B99.0.0.0&uamb=0&uam=&uap=Windows&uapv=19.0.0&uaw=0&are=1&pae=1&frm=0&pscdl=noapi&_eu=AAAAAAQ&sst.rnd=1366235291.1748436965&sst.etld=google.si&sst.gcsub=region1&sst.tft=1748436963058&sst.lpc=263066391&sst.navt=n&sst.ude=1&sst.sw_exp=1&_s=1&sid=1748435062&sct=1&seg=1&dl=https%3A%2F%2Fjelovica.com%2F%3Fgtm_debug%3D1748436961752&dr=https%3A%2F%2Ftagassistant.google.com%2F&dt=Home%20-%20Jelovica&_tu=DA&en=page_view&ep.x-fb-ck-fbp=fb.1.1747298448755.765884182288422226&ep.consent_state_ad_storage=false&ep.consent_state_analytics_storage=false&ep.page_hostname=jelovica.com&ep.event_id=1748437267865_17484370655632&tfd=3827&richsstsse",
  "platform": "",
  "logData": {
    "DownstreamContentSize": 65,
    "ResponseStatusCode": 200,
    "Duration": 21825181,
    "RequestContentSize": 0,
    "RequestHost": "stag.jelovica.com",
    "RequestMethod": "GET",
    "RequestUrl": "https://stag.jelovica.com/g/collect?v=2&tid=G-00BPL66LPS&gtm=45je55q0v9100280165z89209721418za204zb9209721418&_p=1748436963058&_dbg=1&gcs=G111&gcd=13r3r3r2r5l1&npa=0&dma_cps=syphamo&dma=1&tag_exp=101509157~103116026~103130498~103130500~103200004~103233427~103252644~103252646~104481633~104481635&ptag_exp=101509157~103116026~103130498~103130500~103200004~103233427~103252644~103252646~104481633~104481635&cid=471502747.1748435063&ecid=1217857293&ul=sl-si&sr=1920x1080&ur=SI&uaa=x86&uab=64&uafvl=Chromium%3B136.0.7103.114%7CGoogle%2520Chrome%3B136.0.7103.114%7CNot.A%252FBrand%3B99.0.0.0&uamb=0&uam=&uap=Windows&uapv=19.0.0&uaw=0&are=1&pae=1&frm=0&pscdl=noapi&_eu=AAAAAAQ&sst.rnd=1366235291.1748436965&sst.etld=google.si&sst.gcsub=region1&sst.tft=1748436963058&sst.lpc=263066391&sst.navt=n&sst.ude=1&sst.sw_exp=1&_s=1&sid=1748435062&sct=1&seg=1&dl=https%3A%2F%2Fjelovica.com%2F%3Fgtm_debug%3D1748436961752&dr=https%3A%2F%2Ftagassistant.google.com%2F&dt=Home%20-%20Jelovica&_tu=DA&en=page_view&ep.x-fb-ck-fbp=fb.1.1747298448755.765884182288422226&ep.consent_state_ad_storage=false&ep.consent_state_analytics_storage=false&ep.page_hostname=jelovica.com&ep.event_id=1748437267865_17484370655632&tfd=3827&richsstsse",
    "RequestProtocol": "HTTP/1.0",
    "response_Cache-Control": "no-cache",
    "response_Content-Type": "text/plain",
    "response_Set-Cookie": "FPID=FPID2.2.RY79bnuZPlCdtSJOCvuM8rEnvAZV7XK14NJ2cU%2BVMK4%3D.1746563669; Max-Age=63072000; Domain=jelovica.com; Path=/; Secure; HttpOnly",
    "response_Trace-Id": "8e66bb13-faf8-4623-9a4b-34f1f0063191",
    "response_X-Accel-Buffering": "no",
    "response_X-Content-Type-Options": "nosniff",
    "request_Accept": "*/*",
    "request_Accept-Encoding": "gzip, deflate, br, zstd",
    "request_Accept-Language": "sl-SI,sl;q=0.9,en-GB;q=0.8,en;q=0.7",
    "request_Priority": "u=1, i",
    "request_Referer": "https://jelovica.com/?gtm_debug=1748436961752",
    "request_Sec-Ch-Ua": ""Chromium";v="136", "Google Chrome";v="136", "Not.A/Brand";v="99"",
    "request_Sec-Ch-Ua-Mobile": "?0",
    "request_Sec-Ch-Ua-Platform": ""Windows"",
    "request_Sec-Fetch-Dest": "empty",
    "request_Sec-Fetch-Mode": "cors",
    "request_Sec-Fetch-Site": "same-origin",
    "TraceId": "8e66bb13-faf8-4623-9a4b-34f1f0063191",
    "request_User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36",
    "request_X-Device-Browser": "Chrome",
    "request_X-Device-Browser-Version": "136.0.0.0",
    "request_X-Device-Engine": "AppleWebKit",
    "request_X-Device-Engine-Version": "537.36",
    "request_X-Device-Mobile": "false",
    "request_X-Device-Os": "Windows",
    "ClientIP": "46.164.51.68",
    "request_X-Stape-User-Id": "608215a697415ba194fee6a46d1be36e"
  }
}

Here’s another request where I think power up was enabled:

{
  "id": "1748438164490790789",
  "date": 1748438164,
  "traceId": "0f14e37a-8d31-4a66-a424-b65e20904f95",
  "type": {
    "type": "access",
    "label": "Access Log"
  },
  "client": {
    "type": "GA",
    "label": "GA4"
  },
  "event": {
    "type": "PageView",
    "label": "Page View"
  },
  "responseStatusCode": "200",
  "requestUrl": "https://stag.jelovica.com/g/collect?v=2&tid=G-00BPL66LPS&gtm=45je55q0v9100280165z89209721418za204zb9209721418&_p=1748438161408&_dbg=1&gcs=G111&gcd=13r3r3r2r5l1&npa=0&dma_cps=syphamo&dma=1&tag_exp=101509157~103116026~103130498~103130500~103200004~103233427~103252644~103252646~104481633~104481635&ptag_exp=101509157~103116026~103130498~103130500~103200004~103233427~103252644~103252646~104481633~104481635&cid=471502747.1748435063&ecid=1217857293&ul=sl-si&sr=1920x1080&ur=SI&uaa=x86&uab=64&uafvl=Chromium%3B136.0.7103.114%7CGoogle%2520Chrome%3B136.0.7103.114%7CNot.A%252FBrand%3B99.0.0.0&uamb=0&uam=&uap=Windows&uapv=19.0.0&uaw=0&are=1&pae=1&frm=0&pscdl=noapi&_eu=AAAAAAQ&sst.rnd=949399239.1748438164&sst.etld=google.si&sst.gcsub=region1&sst.tft=1748438161408&sst.lpc=263066391&sst.navt=r&sst.ude=1&sst.sw_exp=1&_s=1&sid=1748435062&sct=1&seg=1&dl=https%3A%2F%2Fjelovica.com%2F%3Fgtm_debug%3D1748436961752&dr=https%3A%2F%2Ftagassistant.google.com%2F&dt=Home%20-%20Jelovica&_tu=DA&en=page_view&ep.x-fb-ck-fbp=fb.1.1747298448755.765884182288422226&ep.consent_state_ad_storage=false&ep.consent_state_analytics_storage=false&ep.page_hostname=jelovica.com&ep.event_id=1748438362575_17484388617022&tfd=4494&richsstsse",
  "platform": "",
  "logData": {
    "DownstreamContentSize": 65,
    "ResponseStatusCode": 200,
    "Duration": 313385495,
    "RequestContentSize": 0,
    "RequestHost": "stag.jelovica.com",
    "RequestMethod": "GET",
    "RequestUrl": "https://stag.jelovica.com/g/collect?v=2&tid=G-00BPL66LPS&gtm=45je55q0v9100280165z89209721418za204zb9209721418&_p=1748438161408&_dbg=1&gcs=G111&gcd=13r3r3r2r5l1&npa=0&dma_cps=syphamo&dma=1&tag_exp=101509157~103116026~103130498~103130500~103200004~103233427~103252644~103252646~104481633~104481635&ptag_exp=101509157~103116026~103130498~103130500~103200004~103233427~103252644~103252646~104481633~104481635&cid=471502747.1748435063&ecid=1217857293&ul=sl-si&sr=1920x1080&ur=SI&uaa=x86&uab=64&uafvl=Chromium%3B136.0.7103.114%7CGoogle%2520Chrome%3B136.0.7103.114%7CNot.A%252FBrand%3B99.0.0.0&uamb=0&uam=&uap=Windows&uapv=19.0.0&uaw=0&are=1&pae=1&frm=0&pscdl=noapi&_eu=AAAAAAQ&sst.rnd=949399239.1748438164&sst.etld=google.si&sst.gcsub=region1&sst.tft=1748438161408&sst.lpc=263066391&sst.navt=r&sst.ude=1&sst.sw_exp=1&_s=1&sid=1748435062&sct=1&seg=1&dl=https%3A%2F%2Fjelovica.com%2F%3Fgtm_debug%3D1748436961752&dr=https%3A%2F%2Ftagassistant.google.com%2F&dt=Home%20-%20Jelovica&_tu=DA&en=page_view&ep.x-fb-ck-fbp=fb.1.1747298448755.765884182288422226&ep.consent_state_ad_storage=false&ep.consent_state_analytics_storage=false&ep.page_hostname=jelovica.com&ep.event_id=1748438362575_17484388617022&tfd=4494&richsstsse",
    "RequestProtocol": "HTTP/1.0",
    "response_Cache-Control": "no-cache",
    "response_Content-Type": "text/plain",
    "response_Set-Cookie": "FPID=FPID2.2.RY79bnuZPlCdtSJOCvuM8rEnvAZV7XK14NJ2cU%2BVMK4%3D.1746563669; Max-Age=63072000; Domain=jelovica.com; Path=/; Secure; HttpOnly",
    "response_Trace-Id": "0f14e37a-8d31-4a66-a424-b65e20904f95",
    "response_X-Accel-Buffering": "no",
    "response_X-Content-Type-Options": "nosniff",
    "request_Accept": "*/*",
    "request_Accept-Encoding": "gzip, deflate, br, zstd",
    "request_Accept-Language": "sl-SI,sl;q=0.9,en-GB;q=0.8,en;q=0.7",
    "request_Priority": "u=1, i",
    "request_Referer": "https://jelovica.com/?gtm_debug=1748436961752",
    "request_Sec-Ch-Ua": ""Chromium";v="136", "Google Chrome";v="136", "Not.A/Brand";v="99"",
    "request_Sec-Ch-Ua-Mobile": "?0",
    "request_Sec-Ch-Ua-Platform": ""Windows"",
    "request_Sec-Fetch-Dest": "empty",
    "request_Sec-Fetch-Mode": "cors",
    "request_Sec-Fetch-Site": "same-origin",
    "TraceId": "0f14e37a-8d31-4a66-a424-b65e20904f95",
    "request_User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36",
    "request_X-Device-Browser": "Chrome",
    "request_X-Device-Browser-Version": "136.0.0.0",
    "request_X-Device-Engine": "AppleWebKit",
    "request_X-Device-Engine-Version": "537.36",
    "request_X-Device-Mobile": "false",
    "request_X-Device-Os": "Windows",
    "request_X-Gtm-Server-Preview": "ZW52LTN8UHE0aHZqcFc0MUlaMHpyZ2c5cDRud3wxOTcxNmQ5YWM4Y2Q3MDBiOGUwMTY=",
    "ClientIP": "46.164.51.68",
    "request_X-Stape-User-Id": "608215a697415ba194fee6a46d1be36e"
  }
}

Thanks for the information.

You don’t need to use a preview header if you run previews in your browser and generate events from a neighbouring tab.

The preview header is only needed if you want to see events in the preview that are sent outside the browser, usually webhooks.

Also webhooks in general don’t make sense to send to the same origin path - you can just send them to a subdomain.

Hi, @Alex,

Unfortunately I don’t think you addressed my question.

I turned on the preview header because I couldn’t see any requests in the server preview, although I followed your docummentation for same-origin set up with Nginx.

The configuration tag successfully fired with the correct tagging_server_url parameter, being https://jelovica.com/stag. I can even see the request fired in the network tab in devtools.

But for some reason I am not seeing it in the server GTM preview mode, even though both preview windov (web and server) are open, and working.

I might have pasted the wrong requests from the Stape log, but that was just me testing a few things.

My question remains - I set up same origin with Nginx based on your documentation. You can see my config. Why am I not seeing incoming requests in server preview window unless I turn on the preview header power up? Is this normal behavior for settgin up same-origin with Nginx; did I miss something, or is there something missing in your docummentation?

Thanks for the help.

When using same origin events should go into the preview as normal. Requests are just proxied through your ngnix, it shouldn’t affect anything else if everything is configured correctly and you don’t have any other conflicting settings on ngnix.

Are you running the preview on the same origin url or on a subdomain?

In your browser do you see successful requests to the same origin and are they with a 200 response?

Thank you! This was the answer I was looking for. I was running the preview on the subdomain :slight_smile:

1 Like