How to change url params of url on Looker dashboard based on dashboard filters - looker

I have a dashboard in Looker which contains a button that is a url that goes to another look with more granular data than the dashboard. What I want to do is change the url params of this button based on what the user chooses in the filters on the dashboard. Anyone have any ideas?

You can use liquid variables in the URL of the button. There's a specific section on passing filter values.
The tricky part here though, is that the button will need to be based on a query result for this to work. Static text/markdown Dashboard elements do not support liquid, and so you need to have a single value chart that acts as the 'button'. The single value chart will be based on the Explore containing the fields used in the dashboard filters, so that their values are accessible by the liquid.
The easiest way to do this is probably via a dummy dimension, that just selects a string:
dimension: button {
sql: 'Button'
link: {
label: "My Link"
url: "/look/<1234>?f[destination_view_name.field_name]=_filters['view_name.field_name']"
}
}
Where 1234 is the ID of your look, destination_view_name.field_name is the fully scoped field name for the filter in the Look you are linking to, and view_name.field_name is the name of the Explore and field being filtered on in the Dashboard (that you want to carry through to the Look).

Related

How can I inspect the value of a Custom Field in Google Analytics?

I'm using an "Advanced Filter" in my google-analytics profile to concatenate parts of two different fields together and place that value into Custom Field 1:
Is there a way to inspect the value of Custom Field 1 so I can test that the field extractions are working?
Although I haven't found a way to view the value of a custom field directly, if you are just interested in testing that your field extractions are working correctly and/or that your regex values are correct, instead of outputting the value to a custom field, you can temporarily output the value to something that IS visible from the google-analytics UI, such as Request URI. Then change it back to a custom field later after it's been verified that everything else is correct.
Also, be aware that changes to profile filters can sometimes take a while to start showing up in the UI (see https://support.google.com/analytics/answer/1638635?hl=en).
Though, if someone does know of a way to view the value of a custom field directly, that would be even better.

Change block content based on changes in another block

I am experienced Java/C++ programmer, but totally new to Drupal/PHP.
Short question:
How do I refresh all the blocks in my page, based on the input to a particular block?
Exact Scenario:
I am looking to create a website with display and behaviour similar to http://www.google.com/finance. I have started creating a custom module for this in Drupal 7, So we want to have:
a top input block where users can enter a particular company's name.
a main block which starts with general content (e.g. tables plus latest news about the economy etc). As soon as a company is selected in block 1, this changes to news and tables about the chosen company.
a side graph block displaying some relevant graphs etc. Again, when no company is chosen, this could display the general graphs (e.g. S&P, Dow Jones, NASDAQ), and when a company is chosen, this displays the details for the chosen company.
The way I see it, the website works in a "current context" for the user. So, perhaps I can set a session level variable in Drupal, and refresh all blocks based on the current value of this variable?
However, I am not sure how to achieve this, and what is the best way to do this? (AJAX? Taxonomy?)
Any pointer, hints, suggestions, examples, sample code are most welcome.
This is how I would approach this problem based on how you have described it. The majority of the functionality being handled by the Views module.
I'm assuming you have the following setup:
A Taxonomy vocabulary called "companies" which has company names as
terms.
A Content Type called "News", which has news information about
companies. Most importantly it will need a taxonomy field where you
can select which companies it is related to (lets call this field "company_reference")
A Content Type called "Tables"(?). I'm not sure what information you
want in your "tables", but again it's most important that is has a
taxonomy field to reference companies. (can be the same field "company_reference")
The Majority of the functionality you are looking for can be built using the Views module.
I would create a View (let's call it "Company Data"). the view is going to have three different displays, each of type "block".
Display 1: Input Block
Set the display name to something meaningful, say "user_input_block"
For this block, leave FORMAT settings as they are.
For the FIELDS settings, just have "Content: Title" (does not
really matter for this block).
For the FILTER CRITERIA settings, add a filter and select your
"company_reference" field, set it to auto-complete, expose the filter
to visitors and (under the "more" section) change its Filter Identity
to "company".
For the PAGER settings set it to display a specific number of items and set it to '1'. (this will limit the data this block retrieves)
Under the Advanced section change the "Machine Name" so comething meaningful, say "user_input_block"
Still in the Advanced section click on "Theme: Information". this will display a list of the different custom template files you can have for this view. For "Display Output" write down the last template suggestion in the list, it will be something like "views-view--company-data--user-input-block.tpl.php" ("views-view--{your view name}--{your display name}.tpl.php"). Click on "Display Output" and copy the PHP it lists. (this is the views default PHP for the view).
In a text editor/IDE (whatever you use) paste the copied PHP code and save it in your custom theme with the template name you wrote down. Edit the PHP and either comment out or remove the section that says "<?php if ($rows): ?>...<?php endif; ?>" (this will remove the returned content from the display)
So to review the view display that was just created will (using the custom template) display a block with just a field that as the user is entering a company name it will autocomplete. It will then submit the form and pass it as a GET variable to the current url (www.yoursite.com/yourpage?company=users company").
Display 2: ** Main Block**
Set the display name to something meaningful , say "company_news".
Set the FORMAT settings to which ever you like (or leave as is)
For the FILTER CRITERIA add a "Content:type" filter and select your "News" and "Tables" content types.
In the Advanced section click "add" next to "Contextual Filters". )A contextual filter is passed in the URL, we are going to be grabbing the value that was passed from the Input block.) Select "Content: field_company_reference" as the field and click "Apply"
for the "when the Filter value is Not available" section select "provide default value"
for the "Type" select "PHP code" and the PHP code will be something like this "return isset($_GET['company']) ? $_GET['company']:false;"
for the "When the filter is available of a default is provided", check "Specify validation criteria", set "Validator" to "Taxonomy term", check the "Companies" vocabulary and for "Filter value type select "Term name converted to Term ID"
for "action to take if filter value does not validate" select "display all results"
To review, this view display will display a block that lists "news" and "tables" content. If the GET variable "company" is passed (from the input block) then the content of this block will be filtered to display only content that is associated to that block.
Display 3: ** Graph Block**
I'm not exactly sure what data you want to display in this block (or rather where it would be coming from) but if you set it up like how I described setting up the Main Block it will filter by company (use the same contextual filter and content that has the company taxonomy reference field).
The one difference with this approach is that it requires the page to be reloaded when a user enters a company into the input block. If you want to avoid this then you could make the following changes;
for the main block and graph blocks instead of using a contextual filter use a regular filter for the Company reference field (same settings as were setup in the input block). For both these blocks under the Advanced section, set "Use AJAX" to "Yes", and use custom CSS to hide the exposed filters from view.
with a custom module (or with your custom theme) that adds additional JS to the page. Have the JS triggered by the field in the input block, when a user enters a value into it, the JS copies that value into the exposed (but hidden) field for the other blocks, triggering Drupal to reload them via AJAX with the passed filter.
I haven't tested any of this and it is just theoretical based on my knowledge of Drupal, but it should start you out on the right path.

Drupal 7 View to list content created by logged in user

I've just started using D7 and was trying to set up a system where people can add a couple types of content and associate one with the other via nodereference.
I only want users to be able to see and work with their own content.
To achieve this in D6 I used a view for nodereference.
In D6 I used argument : user: uid and if there is no arg, it uses the user id of the logged in user. This would return all of the content that was authored by the user.
I haven't been able to figure out how to do this in Views 3?
got it:
you first need to add a User relationship, then you will see new filters and contextual filters - one of which is "current user" or something like that
This five minute video shows how to do it, as well: http://nodeone.se/sv/node/684
With contextual filters you can also display the list as a tab on each user page (as shown in the screencast).
If you're interested in a list that always shows the current user's posts, you can use a standard filter instead – there is a "current user" filter available.
Edited: The original link is broken. I'm not sure which video it was, but it could be one of the following (which all deal with this topic).
https://vimeo.com/22276809 Video guide
https://vimeo.com/33588889 Exercise description
https://vimeo.com/33588956 Exercise solution
For drupal 7
Steps for doing as the above question are
Create a new content view and limit it to the content type you want.
Uncheck "Create a page" and check "Create a block." Select the format you want; I recommend an HTML list of linked titles. Click "Continue & edit."
Add a contextual filter for "Content: Author uid."
Under "When the filter value is not available," select "Provide a default value," and select "User ID from URL" from the dropdown. Because blocks don't understand contextual filters very well, the view won't work properly without this default value, and all posts of the given content type will show on all user pages (not just the user's own posts).
Under "When the filter value is available or a default is provided," check "Specify validation criteria" and select "Basic validation" as the validator. Select "Hide view" from the dropdown.
Save your view.
Assuming that you created a block display, the block will now be available on the Blocks page. Go there and open it.
Set your block to display on all user pages (/user/*) in the correct region. Save the block.
Your block should now appear on all user pages, showing the content written by each user.
Source

Search forms linking to actual search page

I have created a search page uising exposed filters and views module. The user can choose from different values in order to get a table with specific results (returning node fields). This page is located under mysite.com/search. The problem is that I would like to put a simplified version of the search form on my homepage (lets say just the keyword search box + one or two checkboxes). This can be a block or a view. When the user presses the search button I would like to redirect him to the search page and show the results. Here the user shall be able to refine his search in an ordinary way. I guess this can be achieved by HTTP GET parameters and pointing to the actual search site. I was wondering however if I could do it without hardcoding the forms on my homepage, i.e. by using views, blocks, etc. I hope this makes sense. Any help will be appreciated.
Edit
The end result is that you want to have one form bring you to the search results page, and another advanced form on the search results page itself. This solution accomplishes this by creating two identical views with different filters for each form.
When someone uses the simplified form, they're taken to example.com/search, and when they're on that page and use the advanced form, they're taken to example.com/search/advanced. Because the views are identical with similar paths, the end user won't know the difference.
Here's how to accomplish this:
Create a view for the search results. Use the default display to set up the search results however you want. For filters, only put in automatic filters: don't put in the stuff you want the user to be able to filter by.
Create a new page display in that view. Give it a path of search. This is going to be the results page that a user hits when they use your simplified search form.
In this page display, override the filters. Set up and expose the filters you want for the simplified search form.
Override Expose form in block in the Basic settings for this display and set it to yes.
Create a new page display in the view, and give it a path of search/advanced. This is going to be the results page that a user hits when they use the advanced search form.
Override the filters for this display, set up and expose the filters you want for the advanced search form.
Override Expose form in block in the Basic settings for this display and set it to yes.
Now, you'll have two view pages, search and search/advanced, and two blocks, a simplified search form and an advanced search form.
Go to the block administration, and enable the simplified search block. Use the path specific visibility settings to set where you want the simplified search box to appear.
Now, enable the advanced search block. Use the path specific visibility settings to set the visibility to:
search
search/*
Let's say you wanted to create another simplified search block with a different set of filters (let's call this alternate). You can do that too: create another page display in your view as you did in steps 2-4 but instead of using the path search, give it a different path: search/alternate. You can add as many simplified forms with different filters as you want, and they'll all have the advanced search form and the same results when you use them.

Create link using View Data

How would I approach this problem:
Background:
I have created a view that displays:
Username, FirstName, LastName, Email
I have added a dropdown filter to the view display that enables the filter of users based on user terms (a user tagging module), Or interests.
That works all good.
The problem:
I now want to add a email group link at the top along side the filter drop down. This link is just an email mailto link that changes dynamically based on the fiter selection.
For example if a filter "A" is chosen and 2 people are displayed as having that tag, the email group link should include the Email address of those 2 people - pretty simple.
How do I go about adding this basic feature?
To do something like this, would probably be easiest in a preprocess function. You only need to loop through all the rows and get all the email addresses, and create the mailto link from that.
You can use the l() function to create mailto links.

Resources