jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/399626 )

Change subject: Add onBeforeInitializeWMDECampaign
......................................................................


Add onBeforeInitializeWMDECampaign

This reverts commit 43178de551536fb544dc79edcc2b60ca80eeacf1
with modifications

This hook no longer triggers a guided tour.
This hook is simply here to allow tracking user registrations
via the Campaigns extension, when the user first lands on a
landing page other than Special:Register

Bug: T182797
Change-Id: I31f63ecd422c9d0757149c3d99b044064dbd4ec3
---
M WikimediaEventsHooks.php
M extension.json
2 files changed, 85 insertions(+), 0 deletions(-)

Approvals:
  Addshore: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/WikimediaEventsHooks.php b/WikimediaEventsHooks.php
index 8b1068c..260a8ab 100644
--- a/WikimediaEventsHooks.php
+++ b/WikimediaEventsHooks.php
@@ -511,4 +511,86 @@
                return true;
        }
 
+       /**
+        * WMDE runs banner campaigns to encourage users to create an account 
and edit.
+        * The tracking already implemented in the Campaigns extension doesn't 
quite cover the WMDE
+        * usecase as they have a wikipage landing page before the user 
progresses to registration.
+        * This could one day be factored out into its own extension or part of 
Campaigns.
+        *
+        * The series of banner campaigns can be seen on Phabricator:
+        * https://phabricator.wikimedia.org/project/subprojects/2821/
+        *
+        * @author addshore on behalf of WMDE
+        *
+        * @param Title $title
+        * @param mixed $unused
+        * @param OutputPage $output
+        * @param User $user
+        * @param WebRequest $request
+        * @param MediaWiki $mediaWiki
+        */
+       public static function onBeforeInitializeWMDECampaign(
+               $title,
+               $unused,
+               $output,
+               $user,
+               $request,
+               $mediaWiki
+       ) {
+               // Only run for dewiki
+               if ( wfWikiID() !== 'dewiki' ) {
+                       return;
+               }
+
+               /**
+                * Setup the campaign prefix.
+                * Everything below this block is agnostic to which tour is 
being run.
+                */
+               $campaignPrefix = 'wmde_etc2017';
+
+               $cookieName = 'wmdecampaign-' . $campaignPrefix;
+               $hasCampaignGetValue = strstr( $request->getVal( 'campaign' ), 
$campaignPrefix ) !== false;
+               $hasCampaignCookie = $request->getCookie( $cookieName ) !== 
null;
+
+               // Get the campaign name from either the URL params or cookie
+               $campaign = 'NULL';
+               if ( $hasCampaignGetValue ) {
+                       $campaign = $request->getVal( 'campaign' );
+               }
+               if ( $hasCampaignCookie ) {
+                       $campaign = $request->getCookie( $cookieName );
+               }
+
+               // Bail if this request has nothing to do with our campaign
+               if ( $campaign === 'NULL' ) {
+                       return;
+               }
+
+               $stats = 
MediaWikiServices::getInstance()->getStatsdDataFactory();
+
+               /**
+                * If an anon user clicks on the banner and doesn't yet have a 
session cookie then
+                * add a session cookie and count the click.
+                */
+               if ( $user->isAnon() && $hasCampaignGetValue && 
!$hasCampaignCookie ) {
+                       $request->response()->setCookie( $cookieName, 
$campaign, null );
+                       $stats->increment( 
"wmde.campaign.$campaign.banner.click" );
+                       wfDebugLog( 'WMDE', "$campaign - 1 - Banner click by 
anon user without cookie" );
+               }
+
+               /**
+                * If an anon user with the cookie, views the create account 
page without a campaign
+                * value set then inject it into the WebRequest object.
+                */
+               if (
+                       $user->isAnon() &&
+                       $hasCampaignCookie &&
+                       $title->isSpecial( 'CreateAccount' ) &&
+                       !$hasCampaignGetValue
+               ) {
+                       $request->setVal( 'campaign', $campaign );
+                       wfDebugLog( 'WMDE', "$campaign - 2 - Inject campaign 
value on CreateAccount" );
+               }
+       }
+
 }
diff --git a/extension.json b/extension.json
index 57cc937..d800aa4 100644
--- a/extension.json
+++ b/extension.json
@@ -14,6 +14,9 @@
                "AuthManagerStatsdHandler": 
"includes/AuthManagerStatsdHandler.php"
        },
        "Hooks": {
+               "BeforeInitialize": [
+                       "WikimediaEventsHooks::onBeforeInitializeWMDECampaign"
+               ],
                "BeforePageDisplay": [
                        "WikimediaEventsHooks::onBeforePageDisplay"
                ],

-- 
To view, visit https://gerrit.wikimedia.org/r/399626
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I31f63ecd422c9d0757149c3d99b044064dbd4ec3
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/WikimediaEvents
Gerrit-Branch: master
Gerrit-Owner: Addshore <addshorew...@gmail.com>
Gerrit-Reviewer: Addshore <addshorew...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to