Custom google analytics reporting - php

Can we add custom variable in google analytics report.
IE: Our URL is as ?module=global_settings&load_tab=global_settings_tab
Can we set a custom variable "module" and "load_tab" using which we cant to track how many hits on which module in reporting.

You could do this via a custom var. Documentation is here, a way to extract url parameters I leave as an exercise to you (hint: better do it serverside). If you want to store both module and tab you'd need two variables, which might in the long run be a problem - there are only five custom vars available (maybe you should store both values in one variable). Custom vars come in different "scopes" (see docs), since this is about page tracking you should use page level scope.
A tracking call for such a custom var might look like this:
_gaq.push(['_setCustomVar',
1, // This custom var is set to slot #1 (from five)
'Path', // The name acts as a kind of category for the user activity.
'global_settings/global_settings_tab', // This value of the custom variable.
3 // Sets the scope to page-level
]);
With Universal Analytics custom vars do not longer exist, they have been replaced by custom dimensions and custom metrics.
But you do not necessarily need a custom var (or custom dimensions), since the url parameters, unless you strip them out explictly in you view settings, will show up in the reports in any case. But those reports won't be particularly beautiful or readable.
To beaufity your reports (if necessary) I'd recommend an advanced filter.
1) Goto view settinsg, new filter , custom, advanced. In the first dropdown select Request Uri as filter field.
2) In the textbox enter module=(.)&load_tab=(.) This is a regular expression that will take the values for your "module" and "load_tab" parameters and store them in a variable.
3) Skip the second filter field.
4) Set "Output to -> constructor" to Request Uri. In the textfield enter /$A1/$A2 - these are the variables that stores the results from Step 2.
So if your url has been "?module=global_settings&load_tab=global_settings_tab" this filter will change it to "/global_settings/global_settings_tab" in the content reports (note that this will break Inpage Analysis, and as always with filtered data you should keep an unfiltered backup profile) - same for any other value of the parameters. That would be more easily readable, and you would not have to waste custom vars (which do not show up in the standard report in any case), so this might be useful

Related

How to add a form field to modx 2.2.14 manager pages

I'm trying to add the editiedon field to the modx manager pages so my users can edit the value using this bit of documentation as a start point:
http://rtfm.modx.com/revolution/2.x/case-studies-and-tutorials/adding-custom-fields-to-manager-forms
Which does work, but:
how can I make that a date/time field?
how can I place it in the settings tab of the given resource?
Isn't input type="date" the answer to the first question? I'm not sure how you would do the second part, unless you managed to get the rendered content and splice it in there somehow (unless theres som hidden specified method).
Otherwise, you could always solve it with regular form customization. You'll want to create a TV of type Date, and give it a custom default data through a snippet, that just fetches the current resources editedon value. I guess you only need to update the resource/update form set. Under the template variables tab of the set, make sure your TV is connected and change the region value of it to "modx-resource-settings"
There are two different ways which have their own pros & cons.
At first you can use template variable with Date type. It gives you correct ExtJS component for dates and you'll see calendar in TV's tab.
If you'll choose this method you have to create a plugin which invokes on OnBeforeDocFormSave event. There you can redefine modResource editedon property from your TV and it will be saved in proper way. Also you may invoke another event(OnLoadWebDocument). There you can set modResource editedon property from you TV if you want to see correct data.
Pros:
fast calendar integration to the one of modResource's tab
you can use Form Customization for security reasons. It's rather easy and from the box.
Cons:
Additional TV which complicates modResource updating process a little bit
Another method is more complicated (you need skills in ExtJS).
Create plugin which invokes on OnDocFormPrerender event. You can add JS to the modResource page there. Your scripts should render new custom tab to the document where you can add your special field with calendar. So there is special ExtJS component in MODX for these purposes. And of course you need events from first method for loading and updating editedon value.
Also you can just render special field to the existing tab instead of creating new tab and rendering your custom field to it.
Pros:
you don't need TV anymore
it's flexible
Cons:
it's more complicated and takes time
P.S. You can view Xlexicon github repo. There you can find example of rendering new tab and manipulation with modResource properties.
Also you can check modAvatar extra for MODX. There is an example of manupulation with existing tab.

Drupal 6 php for node.tpl field contains rather than equal to

I've edited my question as a response to the first commenter.
I'm new to PHP and Drupal templates and an not an experienced programmer.
My organization has events throughout the year. For each event we make recordings, speakers slides and other materials available to either anonymous users or just our members (a custom role). Each event has multiple files and whether they're made available to anonymous users or our members is made a file-by-file basis. So an event can have certain files available to anonymous users and others available only to our members.
We're using the ImageField Extended Fields module to add fields to file uploads and have a checkbox called "Make Public" along with "Description" and "Sort Order" (which I'm hoping can be used to order the files for display on the page... but that's not a priority). A content editor will check the box to make the file available to anonymous users but the default is just for our members.
The first commenter said the field contents look like a serialized array:
a:3:{s:11:"description";s:50:"text text text text text";s:19:"fapi_sort_order_key";a:3:{s:4:"body";s:1:"1";s:6:"format";i:0;s:5:"style";s:9:"textfield";}s:29:"workflow_fapi_make_public_key";i:1;}
I would like to evaluate this field to see whether the "workflow_fapi_make_public_key" portion is 1 or 0 and have the node.tpl.php file display differently depending on the results.
I started with
<?php if ($node->field_eli_event_files_data[0]) : ?>
then moved on to
<?php if (strpos($node->field_eli_event_files_data, '"workflow_fapi_make_public_key";i:0') !== FALSE) : ?>
<h1>Hi there!</h1>
<?php endif; ?>
. The latter statement always came up as false.
Any advice as to how this can be best accomplished would be greatly appreciated.
Thanks.
The value of the field that you have submitted is the serialized form found in the database, i.e. a string used to store the value of a complex variable - an array in this case - in a single database text field. You won't find this string anywhere in the node object. If you need more information on that, please refer to serialize() and unserialize() functions documentation in the php.net site.
If you need to test the value of workflow_fapi_make_public_key you will find it in $node->field_IMAGEFIELD_NAME[0]['data']['workflow_fapi_make_public_key'] (you should verify this via Devel module or another way to inspect the node's content).

Making sure users go through all set up pages in order

Users will enter information on 4 separate pages and click a 'continue' button that takes them to the next page.
I know I shouldn't prevent users from going back and entering information again, but I also need to set up something that doesn't allow users to do something like this:
www.page.com/setup1 -> www.page.com/setup3 -> www.page.com/setup4 -> www.page.com/setup2
Right now they could possibly go in any order they want if they just enter the URL.
$URL = $_SERVER["HTTP_REFERER"];
if($URL == "http://page.com/setup1") { blah blah }
I have a variable that handles the page that they came from, displaying certain information based on that. Is there a way to use that variable to handle my issue? If not, what is the best way to tackle this issue that might arise?
Instead of using four pages, write one and work with JQuery which enables you to show and hide successive fields etc. Use Ajax calls to provide any dynamic information such as selectors based on previous answers. Those can populate DIVs or SPANs which carry hidden default responses . There is at least one excellent Validate plugin that works with JQuery so you ensure all fields are correctly completed.
The advantages are an enhanced user experience, faster responses with reduced server load. It also means that if they want to change earlier data you can handle it all via Ajax and a good plan.
Before adopting the above approach, I used to use one framework page to post back to itself using hidden fields to control the flow, passing data with increasing numbers of post variables and nested if's. I made it managable with lots of include files to do the updates and new fields
My issue was solved through session variables. Each page has a session variable called 'steps'. Each step has a number associated with the page that they are on. If they previous session 'step' was not the correct one, it redirects them to the appropriate 'step' page.
$steps = $_SESSION['steps'];
$_SESSION['steps'] = 3
For example, this must be the 3rd page, or 'step' in the sign up process.
If $steps isn't == 3, I have code that redirects them to the start of the sign up process, destroys the session and they must sign up properly.

Joomla form variable handling

I have a situation where I need to create a shortcut for a specific filter in a Joomla component.
The problem is that I cannot unset it, as I do not know if Joomla sets the form fields to its own session handler, request handler or some kind of custom handler. There also does not appear to be any documentation on this specific case.
The full situation is that I have a link that will auto filter in the same view as another link (in the components sidebar). One view will be just a specific filter and the other is standard. So I need it when you click into the filtered view it will reset the current filters to make sure everything displays as it should, and vice-versa so clicking back will again reset the filters.
I have tried a number of approaches for this, and although I can consistently force it to filter but it will not reset the form when I re-enter the last page with any technique I have tried so far and of course I want to avoid bypassing Joomla's default functions.
if(JRequest::getVar('filter_group_id',false)==10){
JRequest::setVar('last_filter',true);
EthicstoolHelper::addSubmenu('supervisors');
}else{
if(JRequest::getVar('last_filter',false)===true){
JRequest::setVar('last_filter',false);
JRequest::setVar('filter_group_id',false)
}
EthicstoolHelper::addSubmenu('users');
}
This is the most recent think I have tried, as you can see I try to reset the value to false in a hope that Joomla will read it as not being set, as JRequest has no built in unset method.
I don't have enough rep to comment yet, so I'm guessing a bit as to what the problem could be. Assuming that you are using a model to set the state of the filters, you can look at overriding the populateState method.
Another options is to fiddle with the context property in the model. For example, you could change the context if you have your special filters enabled if you are using things like $app->getUserStateFromRequest(). If you can post a bit more information about the design of your component (controllers and models), I can help more.

CakePHP pagination sort (by multiple criteria) issue

I am currently trying to perform pagination using CakePHP's pagination helper.
I have a series of "Listing" rows that are returned and paginated as expected. When the user clicks on the column headings however, I'd like the sort() method to be forced to prioritise certain listings (i.e. priority listings, those with ['Listing']['priority_flag'] = 1) first. However, when the user clicks on the column header, the browser url is set to
www.mysite.com/listing/index/page:1/sort:description/direction:asc
Hence, it is only sorting by description (as the user clicked on the column header for 'description'), ignoring anything to do with priority_flag.
All help appreciated!
gaioshin
I did this by writing an override paginate() function on the appropriate model. For the parameters, look carefully at the structure of the url you have pasted (you can modify it to suit your own ends, but then you would need to deviate from the pagination helper).
It's not difficult to do, but will require some thought. Look at the core to see how it works.

Categories