As more than a few publications have observed, Amazon.com (AMZN) is having a less-than-positive impact on bricks-and-mortar retailers in verticals such as electronics, toys and apparel, and is also steadily taking share from most online rivals, whether or not they have an offline presence. As Jeff Bezos' company keeps expanding with the help of Amazon Prime, a massive fulfillment infrastructure and a sprawling third-party seller marketplace, rivals have become desperate to find ways to stem the tide, whether by coming up with new ways to drive consumers to retail stores or to make their online operations stand out more.

Alphabet/Google (GOOGL) , whose search engine remains a key part of the online shopping activities of many consumers, has long been an important ad partner for many Amazon rivals, and even to some degree (in spite of all the direct and indirect competition between the companies) for Amazon itself. Four moves announced this week show that Google, with the help of its AI strengths, is as hungry as ever about winning more retail ad dollars.

At its annual Google Marketing Next advertiser conference, Google unveiled Attribution, a free software tool that promises to help marketers understand exactly how different ad types (search, display, video, social media, etc.) impacted a consumer's decision to make a purchase. Attribution pulls in data from a slew of major Google ad and analytics products, tracks a user's ad-viewing across devices and uses machine learning to figure out how much different ad types contributed to a sale.

Google also announced a big expansion of its efforts to match online ad clicks with offline shopping activity. Three years after it began measuring when ads led consumers to visit a physical store, Google says it's now able to let Google Search and Shopping ad buyers know how often an ad drove a bricks-and-mortar sale. This is made possible by analyzing online activity, store visits, the data gleaned from retailer loyalty cards and also third-party data that's said to "capture approximately 70% of credit and debit card transactions in the United States."

Sensitive about the privacy fears that such an ad tool would raise, Google insists its solution relies on "a new, custom encryption technology that ensures users' data remains private, secure, and anonymous." It also uses its announcement to claim search advertisers have been able to measure over 5 billion store visits since 2014, and--amid efforts by Facebook  (FB) and others to also link online ad views with real-world actions--that its machine learning and mapping tech is unique in being able to gauge visits in tough settings such as multistory malls and densely populated cities.

Much like the measurement tools that Facebook and Snap (SNAP) have been steadily launching, Attribution and the offline sales measurement service aim to get marketers to spend more on Google ads by giving them a better read on how their ad campaigns are producing actual revenue. Google claims Virgin Holidays found that its search ad campaigns were producing twice as much profit as what was indicated by online performance indicators when in-store sales data was added to the mix.

Google is also now giving search advertisers the ability to target consumers based on shopping "intent signals" gleaned from things like browsing activity and prior searches. For example, a Google Search user who has signaled an interest in traveling to Italy could be shown ads for flights to Rome.

This solution relies on AI to analyze trillions of search queries and site visits to understand what is and isn't a sign of purchase intent. It has already been available for display and YouTube ads, but when it came to search, Google was previously more partial to targeting based on what a user was searching for in a given session, believing this was the best indicator of what someone might be shopping for. The fact that it's now willing to do search targeting based on past online behavior says a lot about how confident it has become about the machine learning algorithms doing the targeting.

Finally, during a talk at the Marketing Next conference, Google ad chief Sridhar Ramaswamy said that the Google Assistant service would be monetized in part by taking a cut on e-commerce transactions that it enables. Such transactional services would have much in common with ability of Amazon's Alexa assistant to handle Amazon orders, and would help address the thorny question of how Assistant will produce revenue when users are primarily engaging with it via voice (rather than also seeing a relevant search ad page). A test in which voice ads promoting Beauty of the Beast were played to Google Home speaker users went about as well as you would expect.

Google's attempts to get online and offline merchants to spend more on search ads have already been paying big dividends. Its Shopping ads, which often appear at the top of a search results page and show an image of a promoted item along with some text, have been a hit, especially on smartphones. Google has also had a decent amount of success at getting local businesses to buy search ads--and more recently, Google Maps ads--meant to drive offline activity (its store visit measurement services have helped).

These efforts helped Google's total paid ad clicks and impressions rise a stunning 44% annually in Q1, with 53% growth seen on Google's own sites and apps. That easily offset the 19% decline seen in average ad price. Booming mobile search ad sales--both for Shopping ads and for text ads promoting everything from travel packages to car insurance--played the biggest role, with YouTube and mobile ad network sales also contributing.

The willingness of retailers not named Amazon to keep hiking their Google ad budgets has helped Google offset the growing tendency of Amazon shoppers to go directly to Amazon's site or app, rather than visit Amazon via Google Search. A Labor Day weekend poll of U.S. consumers by ad firm BloomReach found 55% of respondents saying they go directly to Amazon when first searching for an item, up from 44% a year earlier. The percentage going directly to search engines fell to 28% from 34%.

A U.S. survey done earlier in the year by PowerReviews wasn't as bad for Google: It found 38% of consumers deemed Amazon their preferred starting point for a product search, and 35% chose Google. But both sets of numbers drive home the problem posed by Amazon's continued e-commerce share gains.

Nonetheless, a January 2017 comScore survey found that 71% of retail searches happen on major search engines, and 29% on Amazon. Moreover, with the U.S. e-commerce market still estimated to be growing at a roughly 15% clip, Google and Amazon are battling over a pie that continues to get bigger.

And by developing better tools for understanding how online ads drive offline sales, Google is expanding its addressable market further, making a play to grab more of the physical retail ad dollars that in the past have been directed toward channels such as TV, radio and print. Even with the heavy toll that Amazon and others are exacting on certain segments of traditional retail, that's a giant long-term opportunity with quite a lot of remaining headroom.

Action Alerts PLUS , which Jim Cramer manages as a charitable trust, is long GOOGL and FB.

More from Investing

3 Things Investors Can Do to Stay Strategic When the Market's Volatile

3 Things Investors Can Do to Stay Strategic When the Market's Volatile

How to Be a Tactical Investor in the Current Market

How to Be a Tactical Investor in the Current Market

Canopy Growth CEO: Here's What the Future of Cannabis Looks Like for Investors

Canopy Growth CEO: Here's What the Future of Cannabis Looks Like for Investors

A Guide to Investing in the Fast-Emerging Cannabis Industry

A Guide to Investing in the Fast-Emerging Cannabis Industry

Canopy's CEO and Constellation Brands COO Discuss the Many Uses of Cannabis

Canopy's CEO and Constellation Brands COO Discuss the Many Uses of Cannabis