Regular Expression Match for Google Analytics Goal Tracking - regex

I have a coupon request form on every page on my website, when the coupon form is submitted you are taken to the same page you are on with an additional "?coupon=sent" parameter added to the query string. I would like to be able to track any page url wiht ?coupon=sent on the end as a goal. Currently, I have this:
/[^.][.php][\?coupon\=sent]+
which does not seem to be doing the trick. Any ideas?

Use this one:
/\?coupon=sent/

Related

Is it possible to read tweet-text of a tweet URL without twitter API?

I am using Goose to read the title/text-body of an article from a URL. However, this does not work with a twitter URL, I guess due to the different HTML tag structure. Is there a way to read the tweet text from such a link?
One such example of a tweet (shortened link) is as follows:
https://twitter.com/UniteAlbertans/status/899468829151043584/photo/1
NOTE: I know how to read Tweets through twitter API. However, I am not interested in that. I just want to get the text by parsing the HTML source without all the twitter authentication hassle.
Scrape yourself
Open the url of the tweet, pass to HTML parser of your choice and extract the XPaths you are interested in.
Scraping is discussed in: http://docs.python-guide.org/en/latest/scenarios/scrape/
XPaths can be obtained by right-clicking to element you want, selecting "Inspect", right clicking on the highlighted line in Inspector and selecting "Copy" > "Copy XPath" if the structure of the site is always the same. Otherwise choose properties that define exactly the object you want.
In your case:
//div[contains(#class, 'permalink-tweet-container')]//strong[contains(#class, 'fullname')]/text()
will get you the name of the author and
//div[contains(#class, 'permalink-tweet-container')]//p[contains(#class, 'tweet-text')]//text()
will get you the content of the Tweet.
The full working example:
from lxml import html
import requests
page = requests.get('https://twitter.com/UniteAlbertans/status/899468829151043584')
tree = html.fromstring(page.content)
tree.xpath('//div[contains(#class, "permalink-tweet-container")]//p[contains(#class, "tweet-text")]//text()')
results in:
['Breaking:\n10 sailors missing, 5 injured after USS John S. McCain collides with merchant vessel near Singapore...\n\n', 'https://www.', 'washingtonpost.com/world/another-', 'us-navy-destroyer-collides-with-a-merchant-ship-rescue-efforts-underway/2017/08/20/c42f15b2-8602-11e7-9ce7-9e175d8953fa_story.html?utm_term=.e3e91fff99ba&wpisrc=al_alert-COMBO-world%252Bnation&wpmk=1', u'\xa0', u'\u2026', 'pic.twitter.com/UiGEZq7Eq6']

How do I access my query when using Haystack/Elasticsearch?

I originally followed this tutorial (https://django-haystack.readthedocs.org/en/latest/tutorial.html), and have so far been able to highlight my query within my returned results. However, I want to highlight this same query when visiting the next page that I load with a separate template. Is there any way to save/access this query so that I can highlight the same results within this other template?
Whenever I try and include a statement like this, I get an error, which I'm thinking is because I'm not trying to access the query properly.
{% highlight section.body with query html_tag "span" css_class "highlighted" %}
You have to send to the next page, the information that you use to highlight the results in the first page. You can use the request.session to store the data and call it in the next page, or you can send the sqs by the url to the next page.
If you want to know how to manage the search query set, and how to edit that kind of stuff, I recommend you to read the views.py forms.py and the elasticsearch_backend in the haystack folder at: "/usr/local/lib/python2.7/dist-packages/haystack"
This is the url for the documentation of Django Session: Django Session
This is the url for the documentation to pass parameters trhough url: URL dispatcher

Get comment count on posts across site

I have a site with lots of pages of content and a Facebook comment box (social plugin) on each one. Say, http://subdomain.site.org
I want to build a widget that searches that subdomain for the pages with the most comments on them and list them. Is there a way to do this?
Thanks!
its pretty easy to get the count of comments for each url
use fql:
SELECT url, comment_count, FROM link_stat WHERE url = " http://subdomain.site.org"
you can also get the comment count on all the urls at the same time (depending on how many urls)
SELECT url, comment_count, FROM link_stat WHERE url in ("url1", "url2", "url3" ... )
from facebook -FQL can handle simple math, basic boolean operators, AND or NOT logical operators, and ORDER BY and LIMIT clauses.
fql does not support CONTAINS() or anything else like that to use for searching all url's from a subdomain.
see here for the link_stat table - you can only query on column's that are indexable

'Hiding' form query from URL (Django 1.3)

I have a form with 6-7 fields. After user input, my webapp searches for those fields in a database and displays the results.
Now the issue is, that the URL ends up having all the form field names and their values in it.
result/?name=lorem&class=arc&course=ipsum
Now with the form having 7-8 fields the url ends up looking ugly.
Is there a Django technique to 'hide' these from the URL? Quotes around hide because I'd be okay with a completely different way to pass the objects to my database from the form as well.
Use a POST request. Here's the django docs on forms and a specific example using POST>. HTML-wise, all you need to do is change the method on the form tag.
I do not recommend to use POST requests for search. If you'll use GET it will be easer for user, he can just bookmark a link and save search or share search results with friends.

Get the original path in django

I have a question: how to get the current path of the url. Let's say, I have 3 navigation bars, about , blog and contact page. In each page, I have facebook, twitter and a manual email a friend button. When I clicked the email a friend button, and the current URL is www.example.com/about, the current URL is now already www.example.com/emailafriend. How can I get the www.example/about? Also in blog and contact. Please help me. Thanks.
How does your email a friend button work? Is it a django view that takes the current URL and emails it? If so, you don't want the "current" URL, which, as you note, is actually the email a friend URL. What you want to do is pass the URL you want to share as a URL parameter, ie:
/share?url=http://www.example.com/blog
Adding more info based on comments:
When I was referencing URL above, I was not referring to your django URL configuration. Let's take a step back.
On your About page you have a link to email a friend, right? That link is probably generated in your template, but it's the same on every page. Something like:
Email a friend
Instead of this, try this:
Email a friend
Now you need to make your email_a_friend view handle this. It can get the url via
request.get('url', '').
Some additional information:
You might want to escape the {{ request.get_full_path }} function so that it's escaped and URL safe, then you'll have to unescape it in your view. Once you get the URL back to your view, you can do as you please with it.
{{ request.get_full_path|urlencode }}
Try using Relative URLs like for example From www.example.com/about to get to www.example.com/email use /email. Using relative urls is the simplest solution .
Take a look at this.
Absolute vs relative URLs
It sounds like your want to get the referring URL (the URL that sent you to the current page). That is available to you in the request object, although it is not 100% reliable:
request.META['HTTP_REFERER']
See the documentation on HttpRequest objects for more information.