Javascript tracker not hitting AWS load balancer

Hi

Javascript tracker not hitting AWS load balancer , error is as below:
Access to XMLHttpRequest at ‘htttp:/xxxxxxx/’ from origin ‘http://ec2-xxxxxx:8000/’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: Redirect is not allowed for a preflight request.

The origin server is an ec2 instance has Amazon Linux and Django service running inside Docker.

I am running Django application from within browser.

Within Django home page, I have added javascript tracker as of try pages:

<!-- Snowplow starts plowing -->
        <script type="text/javascript">
        ;(function(p,l,o,w,i,n,g){if(!p[i]){p.GlobalSnowplowNamespace=p.GlobalSnowplowNamespace||[];
        p.GlobalSnowplowNamespace.push(i);p[i]=function(){(p[i].q=p[i].q||[]).push(arguments)
        };p[i].q=p[i].q||[];n=l.createElement(o);g=l.getElementsByTagName(o)[0];n.async=1;
        n.src=w;g.parentNode.insertBefore(n,g)}}(window, document, "script", "{% static 'ecommerce/js/sp.js' %}", "snowplow"));

        window.snowplow('newTracker', 'spmicro', 'htttp:/xxxxxxx/', { // Initialise a tracker
            encodeBase64: false,
            appId: 'sh0pspr33',
            platform: "web",
            discoverRootDomain: true,
            eventMethod: 'post'
        });

        window.snowplow('setUserId', 'tester');

        // activity tracking
        window.snowplow('enableActivityTracking', {
            minimumVisitLength: 20,
            heartbeatDelay: 20
        });

        // form tracking
        var options = {
            forms: {
                denylist: []
            },
            fields: {
                denylist: ['user_password']
            }
        };

        window.snowplow('enableFormTracking', { options: options });

        window.snowplow('trackPageView');
        </script>
        <!-- Snowplow stops plowing -->

Let me know , what I am missing or need any additional configuration.

Hi @achintya.c,

sorry to hear you’re having problems tracking the events.

There are two main things to check:

First, you seem to be using an http URL which might be getting redirected to https leading to 3xx status being passed. And for preflight you need to get a 2xx. Please do make sure that there is no redirect happening on that request as the browser will drop it.

Second, if the request has no Origin header set, the collector sets Access-Control-Allow-Origin to * which will be discarded in newer browsers.

Hi Peel

Thanks for your reply.

I will make the necessary changes and Will post here.

Hi

There seems to be no issue using collector url provided by Snowplow Try, but issue starts when I use AWS collector URL(dns name, autogenerated while installing snowplow using terraform).

Can you please tell me why so?

I am using 2 demo application, one is ReactJS app, another is Django app.

The snowplow try can track events from both the applications but the AWS collector can’t.

Thanks again for your reply.

To clarify, are you using the quickstart modules (GitHub - snowplow/quickstart-examples: Examples of how to automate creating a Snowplow Open Source pipeline) terraform or your own version?

Yes, that is correct.

I have followed the AWS quick start method.

Hi

The issue remains the same.

Can I have an update please?

Have you checked the URL scheme (HTTP/HTTPS) and SSL certificates for the domain are resolving properly. The ones you supplied in the inputs for the modules. You are most likely hitting the first case I mentioned before. Something redirects the OPTIONS request and that must be the ALB.

You can try validating that using for instance curl.

Hi

The curl method says,
‘301 Moved Permanently’.

Now regarding the error: CORS, what are the steps to set ’ Origin header’?

For try , we do not set any origin header but it is working fine and tracking events for my applications.

Thanks again.

Hi

We have able to fix the 301 error, now curl is sending data to S3 bucket.

Questions:

  1. Do I need to add set origin in javascript tracker?
    2.How can I allow load balancer to accept cross region requests through browser?

Many Thanks

Hi

Can I have an update please?

The matter is utmost urgent.

Thanks

Hi @achintya.c, welcome to the community! Just to set expectations, the support you receive here is not likely to be instant. This is an open source community with no guarantee of response times.

There is a lot of documentation available around Snowplow, but for cloud related issues you’ll need to bring a certain amount of understanding and consult their documentation to fill the gaps.

I hope you’ve found a way forward!

Steve

I can understand, the support is not instant. FYI, I am waiting for a reply for over 17 hours. May be I am asking too fast.

Regarding the snowplow documentation , I have not found any solution regarding CORS policy which is being blocked by modern browsers.

I suppose , you are suggesting me to connect ta AWS devs engineer , which I am doing already.

Thanks again.

Do I need to add set origin in javascript tracker?

You shouldn’t need to unless your environment sets the value to something different than you’re expecting it to do so. The XHR calls issued from within your browser should have those values set properly. Again, unless your runtime environment does something weird.

How can I allow load balancer to accept cross region requests through browser?

This is not something that we’d encourage for users to do as it opens up a security loophole. I believe that there probably is a way to modify the ALB responses for the listener to respond with static 200 and fixed set of CORS-headers when it receives an OPTIONS request. But you’d need to consult AWS docs for that.

My suggestion is you debug the XHR calls being passed around between your application and the collector. The Origin headers are the interesting ones on those requests.
Please keep in mind that we do provide full support and assistance for private SaaS BDP customers for whom we run Snowplow pipelines but we can’t really assist with the kind of work for Open Source users.

2 Likes

Hi

Good news is that , my javascript tracker is working and it is reaching s3 bucket (enriched). Now my question is that, why it is not automatically loading in Postgre Database?

Many thanks

I believe the answer should be somewhere in the postgres loader’s logs. Is the service running? Are you getting any bad events? In more general sense, are there any errors? The logs should provide you the answer.

Hi

Happy new year 2022 to everyone.

The log from ‘postgre loader enriched server’ which shows a lot of different errors. I don’t understand what is the issue with the loader.

The file is not allowed here as it is a csv file.

Let me know how to attach it.

Hello

My javascript tracker is sending data to Postgre Database now.

Hi @achintya.c
That’s great news - thanks for the update.
What was the solution to your problem?
Cheers,
Eddie

The issue was in the iglu config file where the iglu load balancer was not selected correctly.

1 Like