Stop GA reporting from appending the domain to the path when previewing - google-analytics

I'm using Google Analytics to track data across multiple domains in a single profile.
By default, reporting only shows the path, not the full URL. This makes it quite confusing where multiple pages on our different domains have the same paths (e.g. '/index' or '/about').
To get round this, I've implemented the filter advised by Google to display the full URL in reporting:
Filter Type: Custom filter > Advanced
Field A: Hostname Extract A: (.*)
Field B: Request URI Extract: (.*)
Output To: Request URI Constructor: $A1$B1
This works just fine ; the only downside is that using the 'preview link' button in the reporting always appends the domain, resulting in a 404 error.
....clicking the 'link preview' icon results in......
Does anyone know a way around this ; either by preventing GA from appending the domain or a better way of displaying the full URLs in reporting?

Thanks Eike - I took your advice and wrote a small browser extension for Chrome. Obviously this isn't an essential, but I wanted to address it as our marketing team use the feature so frequently.
The manifest json :
{
"manifest_version": 2,
"name": "Analytics cross-domain link shortcut",
"version": "1.0",
"description": "Makes the links shortcuts in analytics work when using a 'full url' filter!",
"content_scripts":
[
{
"matches": ["*://*/*"],
"js": ["myscript.js"],
"run_at": "document_start"
}
]
}
And the script:
if (window.opener && document.referrer == "") {
var currentLocation = window.location.href;
if(currentLocation.indexOf("www.appendedurl.com") > -1) {
var newLocation = currentLocation.substr(30); // where '30' is the length of the appended URL
window.location.href = "http://"+newLocation;
}
}
So it's essentially just snipping off the appended URL (if present) on freshly opened popup windows.

Related

Firebase. How to execute function AND load webpage (hosting) with a URL

I need to execute a Firebase function AND load a page using a single URL.
e.g.
URL = "localhost:5000/cars?make=hyundai&model=elantra"
This URL will load the views/cars/index.html webpage.
This URL will also call the loadCar() Firebase function.
...How can I achieve these two goals? (or is there a better way to achieve this - load a page AND invoke a function)
Current behaviour: It loads the page (achieve 1), but doesn't invoke the loadCar() function (doesn't achieve 2).
FYI my firebase.json:
{
"hosting": {
"public": "functions/views",
"rewrites": [
{
"source": "/cars/**",
"function": "loadCar"
}
]
}
My file directory (arrows pointing to relevant files):
loadCar():
exports.loadCar= functions.https.onRequest((req, res) => {
// const requestedCar = Get requested car info from URL queries.
// Save requestedCar to Firestore DB, so it can be loaded in the html view.
// ... etc.
res.end();
});
If you're asking if it's possible for a single Firebase Hosting URL to both load static content and trigger a function, it's not possible. It has to be either one, not both.
You could instead have some JavaScript code in the static content invoke the function through another URL. Or you could have the URL invoke the function, which returns HTML to display, in addition to performing other work. But the destination of the requested URL can only go to static content or a function, not both.

How to create a firebase dynamic link with the REST API

I'm trying to generate a dynamic link in firebase using the REST API. I've tried following instruction on the following page of the documentation: https://firebase.google.com/docs/dynamic-links/rest#create_a_short_link_from_parameters
My apologies in advance for bad formatting, but my request looks something like this:
POST https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=
with headers:
Content-Type: application/json
and body:
{
"dynamicLinkInfo":{
"domainUriPrefix":"https://<myDomain>.page.link/",
"link":"https://www.google.com/",
"androidInfo":{
"androidPackageName":"com.<companyName>.<appname>"
}
}
}
The response i get is:
{
"error": {
"code": 400,
"message": "Invalid Dynamic Link domain: '' or Domain Uri Prefix: 'https://<myDomain>.page.link/'. Expecting exactly one. Dynamic Link Domain isPresent = false, Domain URI prefix isPresent = false, [https://firebase.google.com/docs/dynamic-links/rest#create_a_short_link_from_parameters]",
"status": "INVALID_ARGUMENT"
}
}
My firebase project has a the .page.link domain registered within the project. In the dynamic links section of the firebase project it does show up. I've tested creating links in the firebase console and i've even been able to manually make dynamic short-links using the react-native-firebase package so i'm pretty sure nothing is wrong with my project.
You cannot have / at the end of domainuriprefix. Can you try removing it?
I want to add another solution.
In my case a simple white space in front of 'https' was the trigger.
"message": "Invalid Dynamic Link domain: '' or Domain Uri Prefix: ' https://[...]'
You do need to add the https:// portion to your domainUriPrefix ->
{
"dynamicLinkInfo":{
"domainUriPrefix":"<myDomain>.page.link",
"link":"https://www.google.com/",
"androidInfo":{
"androidPackageName":"com.<companyName>.<appname>"
}
}
}

Google Analytics API - Get page view information for specific URLs

I am looking to implement a page view tracking system on one of my websites.
The website is a directory where suppliers can advertise their services. Suppliers have a unique profile page on the site, e.g mysite.com/directory/abc-profile.html
The idea is that suppliers can log in to their account area on the site and view stats on how many people are visiting their profile. Ideally I want to display this as :
Total views | Total today | This week | This month | This year
It does not matter if the data is not completely up to date.
I already have Google Analytics tracking code installed on the site. Is it possible to use the Google Analytics API to retrieve this data? If so, what kind of query do I need to make? I had a look on the documentation but could not figure whether the functions allow this or not.
I am using PHP and MySQL on the server.
Yes - you will need to use the Google Analytics API for this. I would suggest checking out the Query Explorer to get a feel for the queries you will need to create.
You will require numerous queries to get all the data you need (adjusting the starting date):
- Total Views
- This Year
- This Month
- This Week (i.e. last 7 days - from which you could also get Total Today).
Here is an example query:
https://www.googleapis.com/analytics/v3/data/ga?ids=ga:1234456789&dimensions=ga:pagePath&metrics=ga:pageviews&filters=ga:pagePath==/about-us.html&start-date=2013-10-15&end-date=2013-10-29&max-results=50
Alternatively, you might want to consider www.embeddedanalytics.com (disclosure - I work with them). We have a service/platform that allows website owners to embed GA based charts/statistics without having to learn the GA API. We have a CMS version which will do exactly what you need (where you script the call to pass the page path). We have done something like this with a number of podcast sharing sites.
Google suggests using Reporting API V4 now. The accepted answer uses V3.
Here is a V4 request example:
POST https://analyticsreporting.googleapis.com/v4/reports:batchGet?key={YOUR_API_KEY}
{
"reportRequests": [
{
"viewId": "YOUR_VIEW_ID",
"dimensions": [
{
"name": "ga:pagePath"
}
],
"metrics": [
{
"expression": "ga:pageviews"
}
],
"dimensionFilterClauses": [
{
"filters": [
{
"operator": "EXACT",
"dimensionName": "ga:pagePath",
"expressions": [
"/your-path"
]
}
]
}
],
"dateRanges": [
{
"startDate": "2009-12-31",
"endDate": "2016-09-28"
}
]
}
]
}
where
YOUR_API_KEY - for auth related things follow this page
YOUR_VIEW_ID - you can use the Account Explorer to find a View ID. (or Admin -> View -> View Settings -> View ID).
For more documentation details and a "Try it!" console follow this page.
You should be able to add a filter on the landing page. I am assuming that each user's site has its own start page. This returns only the data for that user. If you want the code on how to do this I suggest you google: Google analytics core reporting API PHP tutorial
Another idea would be to let the user add there Google Analytics account to there profile. Then you can output the google analytics code onto there page. Then they can track there own google analytics data and you won't need to deal with any of it.
Thought I would provide an updated version as the others are showing for V3 and V4 - for anyone using the latest API for Google Analytics Data API (GA4). This is just grabbing the total users, over a date range for a specific path.
Note that the POST is hitting the v1 beta address as this was the latest at the time.
POST https://analyticsdata.googleapis.com/v1beta/properties/PROPERTY_ID:runReport
{
"dateRanges": [
{
"startDate": "YYYY-MM-DD",
"endDate": "YYYY-MM-DD"
}
],
"dimensions": [
{
"name": "pagePath"
}
],
"dimensionFilter": {
"filter": {
"fieldName": "pagePath",
"stringFilter": {
"matchType": "CONTAINS",
"value": "/YOUR/PATH"
}
}
},
"metrics": [
{
"name": "totalUsers"
}
]
}

Extjs 4 - Retrieve data in json format and load a Store. It sends OPTION request

I'm developing an app with Spring MVC and the view in extjs 4. At this point, i have to create a Grid which shows a list of users.
In my Spring MVC controller i have a Get method which returns the list of users in a jsonformat with "items" as a root.
#RequestMapping(method=RequestMethod.GET, value="/getUsers")
public #ResponseBody Users getUsersInJSON(){
Users users = new Users();
users.setItems(userService.getUsers());
return users;
}
If i try to access it with the browser i can see the jsondata correctly.
{"items":[{"username":"name1",".....
But my problem is relative to request of the Ext.data.Store
My Script is the following:
Ext.onReady(function(){
Ext.define('UsersList', {
extend: 'Ext.data.Model',
fields: [
{name:'username', type:'string'},
{name:'firstname', type:'string'}
]
});
var store = Ext.create('Ext.data.Store', {
storeId: 'users',
model: 'UsersList',
autoLoad: 'true',
proxy: {
type: 'ajax',
url : 'http://localhost:8080/MyApp/getUsers.html',
reader: {type: 'json', root: 'items'}
}
});
Ext.create('Ext.grid.Panel',{
store :store,
id : 'user',
title: 'Users',
columns : [
{header : 'Username', dataIndex : 'username'},
{header : 'Firstname', dataIndex: 'firstname'}
],
height :300,
width: 400,
renderTo:'center'
});
});
When the store tries to retrieve the data and launchs the http request, in my firebug console appears OPTIONS getUsers.html while the request in the browser launchs GET getUsers.html
As a result, Ext.data.Store has not elements and the grid appears with the columnames but without data. Maybe i've missed something
Thank you
You can change the HTTP methods that are used by the proxy for the different CRUD operations using actionMethods.
But, as you can see in the doc (and as should obviously be the case), GET is the default for read operations. So the OPTIONS request you are observing is quite puzzling. Are you sure that there's not another part of your code that overrides the default application-wide? Maybe do a search for 'OPTIONS' in all your project's JS files, to try and find a possible suspect. Apparently there's no match in the whole Ext code, so that probably doesn't come from the framework.
Edit:
Ok, I think I've got it. If your page is not accessed from the same domain (i.e. localhost:8080, the port is taken into account), the XHR object seems to resort to an OPTIONS request.
So, to fix your problem, either omit the domain name completely, using:
url: '/MyApp/getUsers.html'
Or double check that your using the same domain and port to access the page and make the requests.

Drupal Rules + one-time-login redirect issue

Problem is as follows:
I have a rule which redirects users to a landing page after login. It works fine.
However, if a user forgets their password, they are sent a link to the one-time-login page. They click the button and (because of my rule) are sent to their landing page.
The problem of course is that they cannot then change their password because the normal password change (in the user profile) requires you know your password to change it.
So how would I modify my redirect rule to say:
"Redirect to landing page, unless the logging-in user is coming from the one-time-login screen" or "Redirect to the landing page, unless the target URL starts with /user/reset/* (can you wildcard??)"
Thanks in advance for any tips
You can do that with a rule like that:
{ "rules_after_login_redirect_to_news" : {
"LABEL" : "After login redirect to news.",
"PLUGIN" : "reaction rule",
"WEIGHT" : "0",
"REQUIRES" : [ "rules" ],
"ON" : [ "user_login" ],
"IF" : [
{ "NOT text_matches" : {
"text" : [ "site:current-page:path" ],
"match" : "^user\/reset\/",
"operation" : "regex"
}
}
],
"DO" : [ { "redirect" : { "url" : "news" } } ]
}
}
I fixed this problem just using rules, as outlined in another answer here but i had to modify it to work, i had to set the Text comparison condition to negative, and the page redirect to Force redirect, and the page i wanted was called 'getting-started'. Works Perfect
So the rule i added:
EVENTS
User has logged in
CONDITIONS
NOT Text comparison
Parameter: Text: [site:current-page:path], Matching text: user, Comparison operation: starts with
ACTIONS
Page redirect
Parameter: URL: getting-started
In the project I'm currently working on I encountered the same problem.
We solved it by using the Context module (http://drupal.org/project/context).
Install and enable the Context module.
Create a context with the condition :
path = ~user/reset/*
(Leave reactions empty)
Use this context as an condition in the login redirect rule
(Context rules / is a context set)
You can also fix this problem just using the module rules, no coding.
In my case I wanted to redirect people to their workbench after they login.
But people that forgot their password would also get redirected to their workbench and wouldn't be able to change their password. They had to navigate to their own profile page but they had to reenter their password again: the onetime logging didn't work anymore.
So this is the rule I added:
Events
Event: User logged in.
Conditions
Elements: Text comparison.
Parameter: Tekst: [site:current-page:path], Matching text: user, Comparison operation: ends with
Actions
Elements: Page redirect
Parameter: URL: admin/workbench, Force redirect: false
There is a Path Rules module and Rules Bonus Pack module that could do this nicely in Drupal 6. But unfortunately it looks like this feature/module is not coming for Drupal 7. See http://drupal.org/node/1506298 and http://drupal.org/node/1045964#comment-6016904
However, you still can use PHP condition to check the path.
Try this (add a new condition and use php to add this. You will need php module enabled).
In the Rules that redirects users after logging in,
<?php
if (arg(0) == 'user' && arg(1) == 'reset'){
return FALSE;
}
else{
return TRUE;
}
?>
This will prevent the Rule from continuing if the path us user/reset/*.
Also, probably you will need the same condition with TRUE False exchanged in another Rule that redirects password-change users.

Resources