Google Analytics, Server-Side Tracking & Bot Filter
up vote
6
down vote
favorite
When submitting an event, using the Google Analytics Measurement Protocol... GA is classifying the events as bot traffic. I can determine this by configuring two views in GA, one with bot filtering on, and one with bot filtering disabled. The events show up consistently in the view with bot filtering disabled.
We do not want to disable the bot filter in our primary view, as this would include a ton of unnecessary bot traffic.
What about this code is tripping up the bot filter?
payload = {
'v': 1,
't': 'event',
'tid': tracking_id,
'ec': category,
'ea': action,
'el': label
}
if value and type(value) is int:
payload['ev'] = value
if user_id:
payload['uid'] = user_id
else:
payload['cid'] = str(uuid4())
requests.post(
'https://www.google-analytics.com/collect',
data=payload,
headers=requests.utils.default_headers()
)
python google-analytics
add a comment |
up vote
6
down vote
favorite
When submitting an event, using the Google Analytics Measurement Protocol... GA is classifying the events as bot traffic. I can determine this by configuring two views in GA, one with bot filtering on, and one with bot filtering disabled. The events show up consistently in the view with bot filtering disabled.
We do not want to disable the bot filter in our primary view, as this would include a ton of unnecessary bot traffic.
What about this code is tripping up the bot filter?
payload = {
'v': 1,
't': 'event',
'tid': tracking_id,
'ec': category,
'ea': action,
'el': label
}
if value and type(value) is int:
payload['ev'] = value
if user_id:
payload['uid'] = user_id
else:
payload['cid'] = str(uuid4())
requests.post(
'https://www.google-analytics.com/collect',
data=payload,
headers=requests.utils.default_headers()
)
python google-analytics
Just a heads up: the indentation on therequests.post()
call is off by two spaces. I can't edit it myself, because the diff is too small for SO to allow! :)
– s3cur3
Nov 30 at 20:25
1
@s3cur3 Fixed! Sorry about that.
– Travis Swientek
Dec 3 at 19:28
add a comment |
up vote
6
down vote
favorite
up vote
6
down vote
favorite
When submitting an event, using the Google Analytics Measurement Protocol... GA is classifying the events as bot traffic. I can determine this by configuring two views in GA, one with bot filtering on, and one with bot filtering disabled. The events show up consistently in the view with bot filtering disabled.
We do not want to disable the bot filter in our primary view, as this would include a ton of unnecessary bot traffic.
What about this code is tripping up the bot filter?
payload = {
'v': 1,
't': 'event',
'tid': tracking_id,
'ec': category,
'ea': action,
'el': label
}
if value and type(value) is int:
payload['ev'] = value
if user_id:
payload['uid'] = user_id
else:
payload['cid'] = str(uuid4())
requests.post(
'https://www.google-analytics.com/collect',
data=payload,
headers=requests.utils.default_headers()
)
python google-analytics
When submitting an event, using the Google Analytics Measurement Protocol... GA is classifying the events as bot traffic. I can determine this by configuring two views in GA, one with bot filtering on, and one with bot filtering disabled. The events show up consistently in the view with bot filtering disabled.
We do not want to disable the bot filter in our primary view, as this would include a ton of unnecessary bot traffic.
What about this code is tripping up the bot filter?
payload = {
'v': 1,
't': 'event',
'tid': tracking_id,
'ec': category,
'ea': action,
'el': label
}
if value and type(value) is int:
payload['ev'] = value
if user_id:
payload['uid'] = user_id
else:
payload['cid'] = str(uuid4())
requests.post(
'https://www.google-analytics.com/collect',
data=payload,
headers=requests.utils.default_headers()
)
python google-analytics
python google-analytics
edited Dec 3 at 19:27
asked Nov 20 at 15:46
Travis Swientek
847713
847713
Just a heads up: the indentation on therequests.post()
call is off by two spaces. I can't edit it myself, because the diff is too small for SO to allow! :)
– s3cur3
Nov 30 at 20:25
1
@s3cur3 Fixed! Sorry about that.
– Travis Swientek
Dec 3 at 19:28
add a comment |
Just a heads up: the indentation on therequests.post()
call is off by two spaces. I can't edit it myself, because the diff is too small for SO to allow! :)
– s3cur3
Nov 30 at 20:25
1
@s3cur3 Fixed! Sorry about that.
– Travis Swientek
Dec 3 at 19:28
Just a heads up: the indentation on the
requests.post()
call is off by two spaces. I can't edit it myself, because the diff is too small for SO to allow! :)– s3cur3
Nov 30 at 20:25
Just a heads up: the indentation on the
requests.post()
call is off by two spaces. I can't edit it myself, because the diff is too small for SO to allow! :)– s3cur3
Nov 30 at 20:25
1
1
@s3cur3 Fixed! Sorry about that.
– Travis Swientek
Dec 3 at 19:28
@s3cur3 Fixed! Sorry about that.
– Travis Swientek
Dec 3 at 19:28
add a comment |
1 Answer
1
active
oldest
votes
up vote
7
down vote
accepted
requests.utils.default_headers()
gives you a the default user agent of "python-requests" (per the code for default_headers()
and default_user_agent()
).
Announcing that you're a Python program—presumably calling their servers up repeatedly from the same IP—sounds like the definition of a bot! :)
You might have better luck lying about your user agent—by grabbing the user agent string from your (real) web browser, for instance.
Wow. That fixed it! Thanks!
– Travis Swientek
Dec 3 at 19:53
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53396644%2fgoogle-analytics-server-side-tracking-bot-filter%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
7
down vote
accepted
requests.utils.default_headers()
gives you a the default user agent of "python-requests" (per the code for default_headers()
and default_user_agent()
).
Announcing that you're a Python program—presumably calling their servers up repeatedly from the same IP—sounds like the definition of a bot! :)
You might have better luck lying about your user agent—by grabbing the user agent string from your (real) web browser, for instance.
Wow. That fixed it! Thanks!
– Travis Swientek
Dec 3 at 19:53
add a comment |
up vote
7
down vote
accepted
requests.utils.default_headers()
gives you a the default user agent of "python-requests" (per the code for default_headers()
and default_user_agent()
).
Announcing that you're a Python program—presumably calling their servers up repeatedly from the same IP—sounds like the definition of a bot! :)
You might have better luck lying about your user agent—by grabbing the user agent string from your (real) web browser, for instance.
Wow. That fixed it! Thanks!
– Travis Swientek
Dec 3 at 19:53
add a comment |
up vote
7
down vote
accepted
up vote
7
down vote
accepted
requests.utils.default_headers()
gives you a the default user agent of "python-requests" (per the code for default_headers()
and default_user_agent()
).
Announcing that you're a Python program—presumably calling their servers up repeatedly from the same IP—sounds like the definition of a bot! :)
You might have better luck lying about your user agent—by grabbing the user agent string from your (real) web browser, for instance.
requests.utils.default_headers()
gives you a the default user agent of "python-requests" (per the code for default_headers()
and default_user_agent()
).
Announcing that you're a Python program—presumably calling their servers up repeatedly from the same IP—sounds like the definition of a bot! :)
You might have better luck lying about your user agent—by grabbing the user agent string from your (real) web browser, for instance.
answered Nov 28 at 21:37
s3cur3
576220
576220
Wow. That fixed it! Thanks!
– Travis Swientek
Dec 3 at 19:53
add a comment |
Wow. That fixed it! Thanks!
– Travis Swientek
Dec 3 at 19:53
Wow. That fixed it! Thanks!
– Travis Swientek
Dec 3 at 19:53
Wow. That fixed it! Thanks!
– Travis Swientek
Dec 3 at 19:53
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53396644%2fgoogle-analytics-server-side-tracking-bot-filter%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Just a heads up: the indentation on the
requests.post()
call is off by two spaces. I can't edit it myself, because the diff is too small for SO to allow! :)– s3cur3
Nov 30 at 20:25
1
@s3cur3 Fixed! Sorry about that.
– Travis Swientek
Dec 3 at 19:28