Getting user cookies from apps script - cookies

Is there an alternative to this javascript:
document.cookie
which can be run inside apps script?
Context:
I'm using Google Analytics Measurement Protocol and is trying to collect __utmz cookie values from inside apps script functions to apply them to:
UrlFetchApp.fetch('https://www.google-analytics.com/collect...............') requests.
That __utmz cookie is being assigned at http://chrome.google.com/webstore/detail/.... page.

You don't need cookies: If users click a link from domain A to domain B you should add the _ga parameter that you get from linkerParam to the link. Then on domain B you should set allowLinker to true for GA to read the value of the _ga parameter and use it to identify the user as being the same as on domain A.

Related

Trying to read a cookie on a different cookie domain using Google Tag Manager

My cookie domain is .mywebsite.com
I also have cookies stored on the domain www.mywebsite.com
I am trying to get Google Tag Manager to "read" a cookie on "www.mywebsite.com" in order to pass to Google Analytics.
Is this possible?
Using the cookie variable, GTM is not able to read the cookie name.
If the cookie has the http-only attribute, you can't read it using JavaScript and/or GTM.
https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies?retiredLocale=de

Setting a Cookie and Defining the Domain: Employee Site (set cookie) > Company Site

I'm trying to filter out employee traffic in Google Analytics via cookie. Our company sets every employee's browser home page to our Intranet (Internal.com). Setting a cookie on Internal.com will give me the best chance at setting cookies for the majority of employees and setting them often.
The problem is, setting a cookie on Internal.com does not translate to Company.com in Google Analytics where I'm actually trying to filter out the traffic.
I do NOT have the ability to change the browser home page to a redirect, such as Company.com/internal > Internal.com.
Is there anyway to allow Company.com to see Internal.com cookies? Is there a way to inject the Google Analytics account ID into the SetCookie function so that it allows it to be read? Are there any other solutions?

STORM CRAWLER : Generate cookie from a separate link via basic authentication and use the cookie to crawl the links in seeds.txt

The website that I want to crawl is enabled with an authentication via a third party basic authentication. For example, the url that needs to be crawled is https://intranet.crawl.com
The url first gets redirected to another page : http://auth.intranet.com, that allows a basic authentication, on passing the valid username and password it uses the cookie to login to https://intranet.crawl.com
How can I achieve the above authentication in storm crawler?
One option would be to use Selenium and have a custom NavigationFilter to fill the credentials on the redirected URL, see tutorial.
You could also generate the cookie externally prior to the crawling and specify it in the seed metadata using the key set-cookie. You'd need to add that key to metadata.transfer in your conf so that it gets transmitted to the outlinks and persisted to the storage.

Should there be multiple _ga tracking cookies for a gtm UA tracked property containing multiple subdomains?

If example.com contains multiple subdomains and all of it resides in a single UA property, assuming subdomain tracking is properly set up in gtm (IE cookieDomain is set to auto and the root domain is on the referral exclusion list for google analytics), should more than one _ga cookie exist on page load when visiting subdomains?
For example, my gtm snippet is included across all subdomains and it fires a pageview UA tag properly and I visit status.example.com, should I see a _ga cookie with an example value of GA1.3.605803990.1475857272 with the status.example.com domain scope and a _ga cookie with an example value of GA1.2.1926999794.1476293458 with the example.com domain scope?
Or should there always be one _ga cookie fixed at just the root domain? I'm trying to determine why my google analytics is still reporting self referrals for both my root domain and subdomain.
If you want to track your domain and subdomains within a single property there should be a single _ga cookie. To make sure there is just one cookie the cookie domain should be set to "auto" when you create the tracker
ga('create','UA-XXXXXXX-X','auto');
which will make sure the cookie is set at the highest possible 'level'. If you get the code from the GA property settings the "auto" setting should already be in there, if you create the tracker via Google Tag Manager you need to explicitly set this via the "set fields" option where you set the field name to "cookieDomain" (GTM has an autosuggest feature that will help with the field names) and the value to "auto".

Django session cookie: from (any) other domain, check if user is logged in

I have a domain domain1.com. The user logs in and a cookie is set. This is done using Django sessions.
I then go to another domain domain2.com. This domain runs javascript. From this javascript, I want to see if the user is logged into domain1.com.
Is this possible? Can I see a cookie belonging to domain1 from domain2? Or can I somehow via ajax make a call domain1 to check if the user is logged in?
Also, the user might originally have logged into domain1 from Chrome, but now they are accessing domain2 from another browser. Aren't cookies browser specific?
EDIT:
The real problem I am trying to solve? (re comment below): I have created a Chrome extension. When the user presses the extension icon from domain2, a javascript is run, which collects information from the page. This information needs to be sent to the user's account on domain1. Note that domain2 can be ANY domain, not one that I have created.
What I tried with AJAX and cookies.
set cookie from domain1:
response.set_cookie("user_cookie", value="somevalue", max_age=60*60, expires=None, path='/', domain=None, secure=None, httponly=False)
Create Python function, which is executed from domain1.com/checklogin:
#csrf_exempt
def is_logged_in(request):
cookie = request.COOKIES.get('user_cookie')
if cookie is not None:
return HttpResponse("1")
else:
return HttpResponse("0")
Go to domain1.com/checklogin -> The response is "1"
Call javascript from domain2 as follows:
var xmlHttp_1=new XMLHttpRequest();
xmlHttp_1.open("POST","http://domain1.com/checklogin/",false);
xmlHttp_1.send();
alert(xmlHttp_1.responseText);
The response here is, incorrectly, 0. It does not see the cookie created by domain1.
Note that domain1 is, at this point, localhost and domain2 is a real domain. Could this be the issue? It does properly call the function.
Is this possible? Can I see a cookie belonging to domain1 from
domain2?
No. Cookies are restricted to domains (and their subdomains). A cookie for .foo.com is accessible to www.foo.com, zoo.foo.com but not bar.com.
Or can I somehow via ajax make a call domain1 to check if the user is
logged in?
This is one way, yes and it will work.
Also, the user might originally have logged into domain1 from Chrome,
but now they are accessing domain2 from another browser. Aren't
cookies browser specific?
Yes, they are. If you are logged into Chrome, and you open Safari, you won't be logged in.
cookies are domain specific, you may share cookies between foo.example.com and bar.example.com but not between two domains. For work around, you need to send ajax request from domain two to domain one and check there if cookie as set and send response back to domain two.
Check this So question for reference:
Setting default cookie domain for Django site with multiple domain names