I want to build a chrome extension which can save the google search text (single English word) with its meaning. E.g. Suppose I have searched for the word "amount" i get the meaning.
"- a quantity of something, especially the total of a thing or things in number, size, value, or extent." Now i want these 2 to store as key value pair in my chrome's local storage. Hope I m cleared.
For this I m using curl and hosted my php page to a server.
$curl = curl_init('http://testing-ground.scraping.pro/textlist');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$page = curl_exec($curl);
if(curl_errno($curl)) // check for execution errors
{
echo 'Scraper error: ' . curl_error($curl);
exit;
}
curl_close($curl);
$regex = '/<div id="case_textlist">(.*?)<\/div>/s';
if ( preg_match($regex, $page, $list) )
echo $list[0];
else
print "Not found";
Code is working fine for static sites or 'dynamic sites with static div', until i got stuck using google search url. The question is how do go to that url for saving the meaning of particular word. Also sometimes I m not able to get the "div" using inspect, in which the actual meaning is written. If I have to go to that "div", then it is must to reach to the url first. Is there any possibility for achieving this. If not just help me out in saving the input value i type on search bar. Thanks.
The Google Web Search API is offcially deprecated, Google excourage developer to use the Custom Search API which may provide solution.
Custom Search Element is a control that provides the user interface for a Google Custom Search Engine. Using the Custom Search Element JavaScript API, you can configure the Google Custom Search UI, search parameters, and result rendering.
It implements the Custom Search Element, which comprises the Custom Search engine and UI. Calling the constructor initializes the Custom Search service and UI; other methods allow you to control search queries, results, and UI.
Syntax:
google.search.CustomSearchControl.CustomSearch
Control(cseId, opt_options);
You can use setOnKeepCallback method. Specifies the optional text label displayed under each search result. Clicking this label triggers a callback into the specified object/method.
google.search.SearchControl.KEEP_LABEL_SAVE sets a label value of save.
Related
I have a little problem setting up a virtualPageView which should override the URL which is sent to google when no result is present.
Heres what I have as JavaScript code:
function returnNoSearchResultsGoogleTagManagerCode($searchterm){
if ($searchterm == "") return "";
$requestUri = $_SERVER['REQUEST_URI'] . "&no_result=".$searchterm;
$js = "<script>
$(document).ready(function(){
dataLayer.push({
'event':'empty_result',
'virtualPageURL':'".$requestUri."'
});
});
</script>";
return $js;
}
As you can see, I want to use an event trigger (empty_result).
In google, I use a Trigger to determine if the Page is a no result Page. First i created a custom Variable with custom JS
function(){
if (document.getElementsByClassName('ga-no-result').length > 0){
return true;
}else{
return false
}
}
The class is set, if the SearchEngine can't find a result. So far so good.
I also created a dataLayer variable to hold the virtualPageURL
Now I need an event which is triggered if the variable is true.
Finally I created a Tag with type PageView which is fired when the event occurs:
Until now it seems okay, the Tag is properly configured (i guess) but if I do a search which has no result, the Page URL is not overridden
The Tag is properly fired and the variables are filled. The overview of the dataLayer shows a correct dataLayer event.
But the PageURL is not overridden... Even if I wait a whole day, the category isn't sent to google.
What am I doing wrong?
I would be very thankful if someone would have an idea or even a solution :)
Thanks in advance
exa.byte
UPDATE:
Hey, I forgot to mention, that I want to use the new page variable as the string which google should use to determine the searchterm and the searchcategory
In Google Analytics I configuered the search as the "q" parameter and the "no_result" as the category.
Is it even possible to change the string which google will parse in the end?
To send a virtual pageview to Google Analytics, the field you need to change is page not {{Page Url}} , also the title field is often used.
That's really the only two things you need to do to send a simple virtual pageview.
Extra: I always start my pagepath with /virtual/ to be able to recognize which ones are virtual pageviews easily in GA
For virtual page view you have to change Field "page" - in your GTM-OnSearchEmptyResult you are changing "{{Page URL}}" - I don't think that's correct way to send virutal pageview. Also if you need to change hostname use Fieldname "hostname".
In preview mode you will not see Page URL changed in Variables Tab, you have to go to the actual GA tag that is fired and check it's values. You can either do this in GTM's preview tool or you can use standard developer tools - Network Tab and see what values are being sent to GA:
You can see "dl" parameter is the current page, if you set up virtual page you should also see parameter called "dp" this is going to be the new value of page in your GA.
If you want to setup virtual pageview you have to use page instead of {{Page URL}} in your fieldname and for Document title use title in you fieldname.
for more field reference of google analytics follow below link
https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#hitType.
If you don't want to mess around with custom Tag Manager events it's still possible to use the good old ga method, even if you don't include the Analytics code on the page. You just need to fetch the right tracker dynamically, as explained by Simo Ahava in this thread.
if (typeof ga === "function") {
ga.getAll().forEach((tracker) => {
tracker.set('page', '/my/path'); // <- change here
tracker.send('pageview');
});
}
I also put it in a gist here.
thanks for your help. I think I got rid of the Problem and have solved it now. I will describe my solution below:
The solution is quite simple.
I had an error/ spelling error # google backend. I set the search_category parameter to "no_results", but used "no_result" for implementation...
Pretty dumb, but sometimes you just won't see the wood for the trees...
I created a new Trigger as helper "HelperDomReady" to trigger the only if DOM is ready and the variable "isEmptySearch" equals "(bool)true"
Now I can see the searchterms which have no result in google backend in the "sitesearch categories" summary. Since I won't set the parameter at all, if the search had at least one hit, the site-search category shows "not-set" for successful results. Therfore the category-section will only show searches without a hit. Problem solved :)
Disadvantage: The searchterm is also listed in the normal list. But I think this is negligible
Is it possible to get the query parameters from google searches?
I.e. if someone googled bicycles the url becomes:
https://www.google.es/search?q=bicycles......
If you then come in the search results and someone clicks to your page you cannot see the query parameters with document.referrer it will only show
https://www.google.es/
Is there a way to know what a visitor searched before coming to your site?
Late response, but I have recently been doing some research and thought that this information may be interesting to other stackoverflow visitors who end up on this page.
Prior to 2016 you could get the url parameters using PHP from the referral data when visitors came to your site via organic search by using server variables:
function get_search_query(){
$query = $_SERVER['QUERY_STRING'];
return (strlen($query)? $query: 'none');
}
or
function get_search_query() {
$query = false;
$referrer = $_SERVER['HTTP_REFERER'];
if (!empty($referrer)) {
//Parse the referrer URL
$parts_url = parse_url($referrer);
// Check if a query string exists
$query = isset($parts_url['query']) ? $parts_url['query'] : '';
return (strlen($query)? $query: false);
}
return $query;
}
However, Google and other search engines have since made it impossible to view the query parameters from organic search and any script like that above returns a blank query string. This is true whether you are logged in to Google or not.
This is unfortunate because this removes valuable information like the the keywords used to find your site. The information still can be found in Google Search Console, but this provides Googles interpretation of what you should see and it is not as direct as getting the information immediately when a visitor hits a page after an organic search.
I am not aware of there being any way to still get organic query parameters.
I found this blog: http://www.powerobjects.com/2016/08/01/advanced-customizations-for-the-custom-tab-in-the-field-service-schedule-board/#collapse2
In it the author describes using configuration to create a new tab in the Field Services Schedule Board by pointing it to a CRM web resource.
The blog includes the following javascript:
function updateBooking()
{
var entityRecordGuid = "10B8A40B-D499-E611-80E6-A45D36FC5A4C";
// GUID is hardcoded to make the sample code easier to understand.
// We can extend this customization to be able to extract the selected booking IDs
// from the SChedule Board's DOM, but that is out of scope for now
var bookableResourceBooking = new XrmServiceToolkit.Soap.BusinessEntity("bookableresourcebooking", entityRecordGuid);
bookableResourceBooking.attributes["cus_urgency"] = document.getElementById('UrgencyInput').value;
bookableResourceBooking.attributes["cus_notes"] = document.getElementById('NoteInput').value;
var updateResponse = XrmServiceToolkit.Soap.Update(bookableResourceBooking);
if (updateResponse == "") { // clear fields if synced to crm
document.getElementById('UrgencyInput').value = "";
document.getElementById('NoteInput').value = "";
} else {
alert('Data didn't sync to CRM');
}
}
The problem that I've got is that I'm not sure how to get the entityRecordGuid value dynamically.
There doesn't seem to be a way of configuring the web resource to
have the selected Item as part of the querystring
There seem to be undocumented JavaScript libraries for Field
Services; however, I can't access them from the web resource IFrame
and of course, they're undocumented.
Has anyone else tried to do this? I'm using CRM Online
I ended up doing this by scraping the HTML directly rather than trying to use any of the API methods from Field One.
This wasn't really a satisfactory answer for me. It depends on the Unscheduled Orders board being in a certain order and since this is changeable by the end-user my solution is very fragile.
For anyone else looking, I did manage to find these API methods; however, I couldn't find any documentation for them so assume that they are unsupported. I also couldn't tie them together to achieve what I wanted
// get the id of the sub grid
F1SDK.SchedulerPage.UnscheduledOrdersGrid.id
// -> "UnscheduledGrid"
F1SDK.SchedulerPage.UnscheduledOrdersGrid.getItemId()
// -> "UnscheduledGrid"
F1SDK.SchedulerPage.UnscheduledOrdersGrid.getStore().storeId
// -> "UnscheduledWorkOrders"
F1SDK.SchedulerPage.UnscheduledOrdersGrid.getStore().data.items[0].internalId
F1SDK.SchedulerPage.UnscheduledOrdersGrid.selModel.selected.items[0].internalId
// Get a subgrid
FieldOneSkyUtils.Subgrid.GetSubgrid('id')
F1SDK.data.models.WorkOrder.getFields()
F1SDK.data.models.WorkOrder.getIdByWONumber('00106')
// -> {55caa97d-429a-e611-80e6-c4346bc4bef0}
I'm trying to figure out how to capture the Adobe Marketing Cloud ID (MID) when a page first loads using a Data Element (or by whatever alternative method will work). My Data Element logic works fine, if the Marketing Cloud cookie already exists. If there is no Marketing Cloud Cookie already existing, my data element reads the Marketing Cloud ID cookie as it is being written but the MID is not populated in the cookie at the time the Data Element reads it.
Is there any way I can access the value and report it in an eVar on the initial page load? I actually take the MID and combine it with an additional value to create the eVar value. As stated my code works unless the Marketing Cloud ID doesn't exist and has to be created during the page load.
You can use Visitor.getInstance() to get the Visitor instance, and then and then Visitor.getMarketingCloudVisitorID() to get the MC ID (what you see in the mid= param)
example:
var visitor = Visitor.getInstance("[mcorgid]#AdobeOrg")
s.eVar1 = visitor.getMarketingCloudVisitorID(); // set v2 with mid= value
If you implemented the MC ID service as a DTM tool, you can alternatively use _satellite.getVisitorId() instead of Visitor.getInstance(), e.g.:
s.eVar1 = _satellite.getVisitorId().getMarketingCloudVisitorID();
So for your Data Element, instead of doing a Cookie type (I assume that's what you did), you will need to use Custom Script type and return the value, e.g.
try {
return _satellite.getVisitorId().getMarketingCloudVisitorID();
} catch(e) {console.log(e);}
(Update) Alternatives
From your comment below (my bold for emphasis):
Just to be clear, this only happens to me on the first page when the
Marketing Cloud cookies don't exist. I do see the MID in the server
call.
Since you have confirmed that AA is getting an mid= value in its request, instead of trying to push the actual value of it to your eVar, you can pop it indirectly in other ways.
Dynamic Variables
dynamic variable syntax to reference the mid= param:
s.eVar1 = "D=mid";
Note: D= is the default dynamic variable prefix syntax. Check your AA tool config/other custom code to ensure it is not being set to something else.
Processing Rules
If you have access to create processing rules, you can setup a processing rule to set your eVar to mid= value there.
hi i'm trying to implement getstream.io in my project.
i'm using https://github.com/GetStream/stream-js
as my server side script is in nodeJS.
i'm able to create a user in feed using
user1 = client.feed('user', 'dpz');
i'm creating activity for this user using using
activity ={
"actor":"user:1",
"message": "#flat_4_bfcaffca-c35f-11e5-8080-8001002e75f6",
"verb":"tweet",
"object":"tweet:4",
"foreign_id": "flat:4"
};
user1.addActivity(activity);
if i want to get all records of that user,
i use
user1.get()
.then(function(body) { console.log(JSON.stringify(body)); })
.catch(function(reason) { console.log(JSON.stringify(reason.error));});
i get result as :
{"duration":"19ms",
"next":"",
"results":[{
"actor":"user:1",
"foreign_id":"flat:4",
"id":"41231d40-ca5a-11e5-8080-800047dac62a",
"message":"#flat_4_bfcaffca-c35f-11e5-8080-8001002e75f6",
"object":"tweet:4",
"origin":null,
"target":null,
"time":"2016-02-03T09:41:09.335584",
"to":[],
"verb":"tweet"
}]
}
in your rest_ documentation
https://getstream.io/docs_rest/#feed_detail
you have specified
feed/(feed_slug)/(user_id)/(activity_id|foreign_id)/
to delete an activity for if the foreign key matches criteria.
in your nodejs code
user1.removeActivity({foreignId: 'flat:4'})
line works to remove the feed for that user where foreign key is flat:4
user1.get({foreignId: 'flat:4'})
does not work
can you please help if i want to get feeds with the foreignId as 'flat:4'
is there any way for such ?
please help as i'm stuck on this point only.
The feed/(feed_slug)/(user_id)/(activity_id|foreign_id)/ endpoint is only for DELETE requests. At this present is not possible to retrieve activities by its foreign_id. That field can only be used to perform cascaded deletion and/or to define the uniqueness of your data.
Looking at the code that you added, it seems like to use references to feeds as the value for foreign_ids, if that's the case then you are probably using this field in a weird/wrong way and you should create a new question on SO to ask help with the integration of your data.